1 /* No user fns here.  Pesch 15apr92. */
2 
3 /*
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation,
10  * and/or other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by the University of California, Berkeley.  The name of the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  */
19 
20 #define _DEFAULT_SOURCE
21 #include <stdio.h>
22 #include <sys/types.h>
23 #include <fcntl.h>
24 #include <sys/unistd.h>
25 #include <errno.h>
26 #include "../stdio/local.h"
27 
28 #ifdef __LARGE64_FILES
29 
30 _off64_t lseek64(int fd, _off64_t offset, int whence);
31 
32 fpos64_t
__sseek64(void * cookie,_fpos64_t offset,int whence)33 __sseek64 (
34        void *cookie,
35        _fpos64_t offset,
36        int whence)
37 {
38   register FILE *fp = (FILE *) cookie;
39   register _off64_t ret;
40 
41   ret = lseek64 (fp->_file, (_off64_t) offset, whence);
42   if (ret == (_fpos64_t)-1L)
43     fp->_flags &= ~__SOFF;
44   else
45     {
46       fp->_flags |= __SOFF;
47       fp->_offset = ret;
48     }
49   return ret;
50 }
51 
52 ssize_t
__swrite64(void * cookie,char const * buf,size_t n)53 __swrite64 (
54        void *cookie,
55        char const *buf,
56        size_t n)
57 {
58   register FILE *fp = (FILE *) cookie;
59   ssize_t w;
60 #ifdef __SCLE
61   int oldmode=0;
62 #endif
63 
64   if (fp->_flags & __SAPP)
65     (void) lseek64 (fp->_file, (_off64_t)0, SEEK_END);
66   fp->_flags &= ~__SOFF;	/* in case O_APPEND mode is set */
67 
68 #ifdef __SCLE
69   if (fp->_flags & __SCLE)
70     oldmode = setmode(fp->_file, O_BINARY);
71 #endif
72 
73   w = write (fp->_file, buf, n);
74 
75 #ifdef __SCLE
76   if (oldmode)
77     setmode(fp->_file, oldmode);
78 #endif
79 
80   return w;
81 }
82 
83 #endif /* __LARGE64_FILES */
84