Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
 
18
/*
19
FUNCTION
20
<>---write a character string in a file or stream
21
 
22
INDEX
23
	fputs
24
INDEX
25
	_fputs_r
26
 
27
ANSI_SYNOPSIS
28
	#include 
4921 Serge 29
	int fputs(const char *restrict <[s]>, FILE *restrict <[fp]>);
4349 Serge 30
 
31
	#include 
4921 Serge 32
	int _fputs_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>);
4349 Serge 33
 
34
TRAD_SYNOPSIS
35
	#include 
36
	int fputs(<[s]>, <[fp]>)
37
	char *<[s]>;
38
	FILE *<[fp]>;
39
 
40
	#include 
41
	int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
42
	struct _reent *<[ptr]>;
43
	char *<[s]>;
44
	FILE *<[fp]>;
45
 
46
DESCRIPTION
47
<> writes the string at <[s]> (but without the trailing null)
48
to the file or stream identified by <[fp]>.
49
 
50
<<_fputs_r>> is simply the reentrant version of <> that takes
51
an additional reentrant struct pointer argument: <[ptr]>.
52
 
53
RETURNS
54
If successful, the result is <<0>>; otherwise, the result is <>.
55
 
56
PORTABILITY
57
ANSI C requires <>, but does not specify that the result on
58
success must be <<0>>; any non-negative value is permitted.
59
 
60
Supporting OS subroutines required: <>, <>, <>,
61
<>, <>, <>, <>.
62
*/
63
 
64
#include <_ansi.h>
65
#include 
66
#include 
67
#include "fvwrite.h"
68
#include "local.h"
69
 
70
/*
71
 * Write the given string to the given file.
72
 */
73
 
74
int
75
_DEFUN(_fputs_r, (ptr, s, fp),
76
       struct _reent * ptr _AND
4921 Serge 77
       char _CONST *__restrict s _AND
78
       FILE *__restrict fp)
4349 Serge 79
{
4921 Serge 80
#ifdef _FVWRITE_IN_STREAMIO
4349 Serge 81
  int result;
82
  struct __suio uio;
83
  struct __siov iov;
84
 
85
  iov.iov_base = s;
86
  iov.iov_len = uio.uio_resid = strlen (s);
87
  uio.uio_iov = &iov;
88
  uio.uio_iovcnt = 1;
89
 
90
  CHECK_INIT(ptr, fp);
91
 
4921 Serge 92
  _newlib_flockfile_start (fp);
4349 Serge 93
  ORIENT (fp, -1);
94
  result = __sfvwrite_r (ptr, fp, &uio);
4921 Serge 95
  _newlib_flockfile_end (fp);
4349 Serge 96
  return result;
4921 Serge 97
#else
98
  _CONST char *p = s;
99
 
100
  CHECK_INIT(ptr, fp);
101
 
102
  _newlib_flockfile_start (fp);
103
  ORIENT (fp, -1);
104
  /* Make sure we can write.  */
105
  if (cantwrite (ptr, fp))
106
    goto error;
107
 
108
  while (*p)
109
    {
110
      if (__sputc_r (ptr, *p++, fp) == EOF)
111
	goto error;
112
    }
113
  _newlib_flockfile_exit (fp);
114
  return 0;
115
 
116
error:
117
  _newlib_flockfile_end (fp);
118
  return EOF;
119
#endif
4349 Serge 120
}
121
 
122
#ifndef _REENT_ONLY
123
int
124
_DEFUN(fputs, (s, fp),
4921 Serge 125
       char _CONST *__restrict s _AND
126
       FILE *__restrict fp)
4349 Serge 127
{
128
  return _fputs_r (_REENT, s, fp);
129
}
130
#endif /* !_REENT_ONLY */