ReactOS 0.4.15-dev-7131-ge4d03f4
filewrite.c
Go to the documentation of this file.
1/* @(#)filewrite.c 1.18 12/02/26 Copyright 1986, 1995-2012 J. Schilling */
2/*
3 * Copyright (c) 1986, 1995-2012 J. Schilling
4 */
5/*
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License, Version 1.0 only
8 * (the "License"). You may not use this file except in compliance
9 * with the License.
10 *
11 * See the file CDDL.Schily.txt in this distribution for details.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file CDDL.Schily.txt from this distribution.
15 */
16
17#include "schilyio.h"
18
19static char _writeerr[] = "file_write_err";
20
21#ifdef HAVE_USG_STDIO
22
25 register FILE *f;
26 void *vbuf;
27 size_t len;
28{
29 register int n;
30 ssize_t cnt;
31 char *buf = vbuf;
32
34
35 if (f->_flag & _IONBF) {
36 cnt = _niwrite(fileno(f), buf, len);
37 if (cnt < 0) {
38 f->_flag |= _IOERR;
39 if (!(my_flag(f) & _JS_IONORAISE))
41 }
42 return (cnt);
43 }
44 cnt = 0;
45 while (len > 0) {
46 if (f->_cnt <= 0) {
47 if (usg_flsbuf((unsigned char) *buf++, f) == EOF)
48 break;
49 cnt++;
50 if (--len == 0)
51 break;
52 }
53 if ((n = f->_cnt >= len ? len : f->_cnt) > 0) {
54 f->_ptr = (unsigned char *)movebytes(buf, f->_ptr, n);
55 buf += n;
56 f->_cnt -= n;
57 cnt += n;
58 len -= n;
59 }
60 }
61 if (!ferror(f))
62 return (cnt);
65 return (-1);
66}
67
68#else
69
72 register FILE *f;
73 void *vbuf;
74 size_t len;
75{
76 ssize_t cnt;
77 char *buf = vbuf;
78
80
81 if (my_flag(f) & _JS_IOUNBUF)
82 return (_niwrite(fileno(f), buf, len));
83 cnt = fwrite(buf, 1, len, f);
84
85 if (!ferror(f))
86 return (cnt);
89 return (-1);
90}
91
92#endif /* HAVE_USG_STDIO */
#define fileno
Definition: acwin.h:102
static char _writeerr[]
Definition: filewrite.c:19
EXPORT ssize_t filewrite(FILE *f, void *vbuf, size_t len)
Definition: filewrite.c:71
EXPORT int _io_glflag
Definition: flag.c:31
GLdouble n
Definition: glext.h:7729
GLfloat f
Definition: glext.h:7540
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define _IOWRT
Definition: stdio.h:125
#define EOF
Definition: stdio.h:24
#define _IORW
Definition: stdio.h:135
#define _IONBF
Definition: stdio.h:129
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define _IOERR
Definition: stdio.h:133
#define f
Definition: ke_i.h:83
EXPORT char * movebytes(void *fromv, void *tov, ssize_t cnt) const
Definition: movebytes.c:30
EXPORT ssize_t _niwrite(int f, void *buf, size_t count)
Definition: niwrite.c:22
#define L(x)
Definition: ntvdm.h:50
EXPORT void raisecond(char *signame, long arg2) const
Definition: raisecond.c:100
int ssize_t
Definition: rosdhcp.h:48
#define _JS_IOUNBUF
Definition: schilyio.h:100
#define _JS_IONORAISE
Definition: schilyio.h:99
#define my_flag(p)
Definition: schilyio.h:137
#define down2(f, fl1, fl2)
Definition: schilyio.h:218
Definition: internal.h:110