Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4874 Rev 4921
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_r
25
	_fputs_r
26
 
26
 
27
ANSI_SYNOPSIS
27
ANSI_SYNOPSIS
28
	#include 
28
	#include 
29
	int fputs(const char *<[s]>, FILE *<[fp]>);
29
	int fputs(const char *restrict <[s]>, FILE *restrict <[fp]>);
30
 
30
 
31
	#include 
31
	#include 
32
	int _fputs_r(struct _reent *<[ptr]>, const char *<[s]>, FILE *<[fp]>);
32
	int _fputs_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>);
33
 
33
 
34
TRAD_SYNOPSIS
34
TRAD_SYNOPSIS
35
	#include 
35
	#include 
36
	int fputs(<[s]>, <[fp]>)
36
	int fputs(<[s]>, <[fp]>)
37
	char *<[s]>;
37
	char *<[s]>;
38
	FILE *<[fp]>;
38
	FILE *<[fp]>;
39
 
39
 
40
	#include 
40
	#include 
41
	int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
41
	int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
42
	struct _reent *<[ptr]>;
42
	struct _reent *<[ptr]>;
43
	char *<[s]>;
43
	char *<[s]>;
44
	FILE *<[fp]>;
44
	FILE *<[fp]>;
45
 
45
 
46
DESCRIPTION
46
DESCRIPTION
47
<> writes the string at <[s]> (but without the trailing null)
47
<> writes the string at <[s]> (but without the trailing null)
48
to the file or stream identified by <[fp]>.
48
to the file or stream identified by <[fp]>.
49
 
49
 
50
<<_fputs_r>> is simply the reentrant version of <> that takes
50
<<_fputs_r>> is simply the reentrant version of <> that takes
51
an additional reentrant struct pointer argument: <[ptr]>.
51
an additional reentrant struct pointer argument: <[ptr]>.
52
 
52
 
53
RETURNS
53
RETURNS
54
If successful, the result is <<0>>; otherwise, the result is <>.
54
If successful, the result is <<0>>; otherwise, the result is <>.
55
 
55
 
56
PORTABILITY
56
PORTABILITY
57
ANSI C requires <>, but does not specify that the result on
57
ANSI C requires <>, but does not specify that the result on
58
success must be <<0>>; any non-negative value is permitted.
58
success must be <<0>>; any non-negative value is permitted.
59
 
59
 
60
Supporting OS subroutines required: <>, <>, <>,
60
Supporting OS subroutines required: <>, <>, <>,
61
<>, <>, <>, <>.
61
<>, <>, <>, <>.
62
*/
62
*/
63
 
63
 
64
#include <_ansi.h>
64
#include <_ansi.h>
65
#include 
65
#include 
66
#include 
66
#include 
67
#include "fvwrite.h"
67
#include "fvwrite.h"
68
#include "local.h"
68
#include "local.h"
69
 
69
 
70
/*
70
/*
71
 * Write the given string to the given file.
71
 * Write the given string to the given file.
72
 */
72
 */
73
 
73
 
74
int
74
int
75
_DEFUN(_fputs_r, (ptr, s, fp),
75
_DEFUN(_fputs_r, (ptr, s, fp),
76
       struct _reent * ptr _AND
76
       struct _reent * ptr _AND
77
       char _CONST * s _AND
77
       char _CONST *__restrict s _AND
78
       FILE * fp)
78
       FILE *__restrict fp)
79
{
79
{
-
 
80
#ifdef _FVWRITE_IN_STREAMIO
80
  int result;
81
  int result;
81
  struct __suio uio;
82
  struct __suio uio;
82
  struct __siov iov;
83
  struct __siov iov;
83
 
84
 
84
  iov.iov_base = s;
85
  iov.iov_base = s;
85
  iov.iov_len = uio.uio_resid = strlen (s);
86
  iov.iov_len = uio.uio_resid = strlen (s);
86
  uio.uio_iov = &iov;
87
  uio.uio_iov = &iov;
87
  uio.uio_iovcnt = 1;
88
  uio.uio_iovcnt = 1;
88
 
89
 
89
  CHECK_INIT(ptr, fp);
90
  CHECK_INIT(ptr, fp);
90
 
91
 
91
  _flockfile (fp);
92
  _newlib_flockfile_start (fp);
92
  ORIENT (fp, -1);
93
  ORIENT (fp, -1);
93
  result = __sfvwrite_r (ptr, fp, &uio);
94
  result = __sfvwrite_r (ptr, fp, &uio);
94
  _funlockfile (fp);
95
  _newlib_flockfile_end (fp);
-
 
96
  return result;
-
 
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;
95
  return result;
119
#endif
96
}
120
}
97
 
121
 
98
#ifndef _REENT_ONLY
122
#ifndef _REENT_ONLY
99
int
123
int
100
_DEFUN(fputs, (s, fp),
124
_DEFUN(fputs, (s, fp),
101
       char _CONST * s _AND
125
       char _CONST *__restrict s _AND
102
       FILE * fp)
126
       FILE *__restrict fp)
103
{
127
{
104
  return _fputs_r (_REENT, s, fp);
128
  return _fputs_r (_REENT, s, fp);
105
}
129
}
106
#endif /* !_REENT_ONLY */
130
#endif /* !_REENT_ONLY */