Subversion Repositories Kolibri OS

Rev

Rev 4921 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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