mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
build: include standards macros for all AST code (re: 7fb814e1)
Turns out that the standards macros set by features/standards (such as _GNU_SOURCE for Linux or _DARWIN_SOURCE for macOS) were still *not* included for most C source files! Instead, they were selectively included for some files only, sometimes via FEATURE/standards (the output of features/standards), sometimes via ast_standards.h which is copied from FEATURE/standards. Consequently, there were still inconsistencies in the system header interfaces exposed on Linux, macOS, Solaris, et al. It's no wonder it sometimes took so much hackery to keep everything building. Of course, making this consistent had to break things somewhere. Breakage occurred on 32-bit Linux due to a lot of ugly hackery involving direct use of internal GNU types like off64_t and functions like fseek64(). This is now all removed and they are activated by setting the appropriate feature macro instead, so these types and functions can be used with their standard names (off_t, fseek, etc.) Before committing I've tested these changes on the following i386/x86_64 systems: Linux (glibc 32 and 64 bit, musl libc 64 bit), Solaris (32 and 64 bit), illumos (32 and 64 bit), FreeBSD (64 bit), macOS (64 bit), Cygwin (32 bit), and Haiku (64 bit). (Note: ast_standards.h is copied from FEATURE/standards, whereas ast_common.h is copied from FEATURE/common.) src/lib/libast/include/ast_std.h, src/lib/libast/stdio/stdhdr.h: - Include <ast_standards.h> first. This should cause all the AST and dependent code (such as ksh) to get the standards macros. src/lib/libast/features/standards: - For GNU (glibc), #define _FILE_OFFSET_BITS 64 to get large file support with 64-bit offsets. - Stop GNU and Cygwin <string.h> form defining the GNU version of basename(3); on Cygwin, that declaration conflicts with the AST version (and with POSIX) by using a const char* argument instead of char*. It is deactivated by defining the macro 'basename' (as 'basename'); this causes GNU string.h to consider it to be already defined by the standard libgen.h header. All other changed files: - Remove direct use of *64* types and functions and a lot of related hackery.
This commit is contained in:
parent
fb8e239cb4
commit
289dd46c05
43 changed files with 78 additions and 872 deletions
|
|
@ -73,9 +73,9 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */
|
|||
if(f->file >= 0 )
|
||||
{ if ((oflags &= (O_TEXT|O_BINARY|O_APPEND)) != 0 )
|
||||
{ /* set file access control */
|
||||
int ctl = sysfcntlf(f->file, F_GETFL, 0);
|
||||
int ctl = fcntl(f->file, F_GETFL, 0);
|
||||
ctl = (ctl & ~(O_TEXT|O_BINARY|O_APPEND)) | oflags;
|
||||
sysfcntlf(f->file, F_SETFL, ctl);
|
||||
fcntl(f->file, F_SETFL, ctl);
|
||||
}
|
||||
#if !O_cloexec
|
||||
if (fflags & SF_FD_CLOEXEC)
|
||||
|
|
@ -96,10 +96,10 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */
|
|||
return NIL(Sfio_t*);
|
||||
|
||||
#if _has_oflags /* open the file */
|
||||
while((fd = sysopenf((char*)file,oflags,SF_CREATMODE)) < 0 && errno == EINTR)
|
||||
while((fd = open((char*)file,oflags,SF_CREATMODE)) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
#else
|
||||
while((fd = sysopenf(file,oflags&O_ACCMODE)) < 0 && errno == EINTR)
|
||||
while((fd = open(file,oflags&O_ACCMODE)) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
if(fd >= 0)
|
||||
{ if((oflags&(O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL) )
|
||||
|
|
@ -108,19 +108,19 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */
|
|||
}
|
||||
if(oflags&O_TRUNC ) /* truncate file */
|
||||
{ reg int tf;
|
||||
while((tf = syscreatf(file,SF_CREATMODE)) < 0 &&
|
||||
while((tf = creat(file,SF_CREATMODE)) < 0 &&
|
||||
errno == EINTR)
|
||||
errno = 0;
|
||||
CLOSE(tf);
|
||||
}
|
||||
}
|
||||
else if(oflags&O_CREAT)
|
||||
{ while((fd = syscreatf(file,SF_CREATMODE)) < 0 && errno == EINTR)
|
||||
{ while((fd = creat(file,SF_CREATMODE)) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
if((oflags&O_ACCMODE) != O_WRONLY)
|
||||
{ /* the file now exists, reopen it for read/write */
|
||||
CLOSE(fd);
|
||||
while((fd = sysopenf(file,oflags&O_ACCMODE)) < 0 &&
|
||||
while((fd = open(file,oflags&O_ACCMODE)) < 0 &&
|
||||
errno == EINTR)
|
||||
errno = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ int sfclose(Sfio_t* f)
|
|||
if(_Sfnotify)
|
||||
(*_Sfnotify)(f, SF_CLOSING, (void*)((long)f->file));
|
||||
if(f->file >= 0 && !(f->flags&SF_STRING))
|
||||
{ while(sysclosef(f->file) < 0 )
|
||||
{ while(close(f->file) < 0 )
|
||||
{ if(errno == EINTR)
|
||||
errno = 0;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -47,22 +47,6 @@
|
|||
/* define va_list, etc. before including sfio_t.h (sfio.h) */
|
||||
#if !_PACKAGE_ast
|
||||
|
||||
/* some systems don't know large files */
|
||||
#if defined(_NO_LARGEFILE64_SOURCE) || _mips == 2 /* || __hppa */
|
||||
#undef _NO_LARGEFILE64_SOURCE
|
||||
#define _NO_LARGEFILE64_SOURCE 1
|
||||
#undef _LARGEFILE64_SOURCE
|
||||
#undef _LARGEFILE_SOURCE
|
||||
#endif
|
||||
|
||||
#if !_NO_LARGEFILE64_SOURCE && _typ_off64_t && _lib_lseek64 && _lib_stat64
|
||||
#undef _LARGEFILE64_SOURCE
|
||||
#undef _LARGEFILE_SOURCE
|
||||
#undef _FILE_OFFSET_BITS
|
||||
#define _LARGEFILE64_SOURCE 1 /* enabling the *64 stuff */
|
||||
#define _LARGEFILE_SOURCE 1
|
||||
#endif
|
||||
|
||||
#if _hdr_stdarg
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
|
|
@ -100,24 +84,6 @@
|
|||
#define _lib_locale 1
|
||||
#endif
|
||||
|
||||
#define sfoff_t off_t
|
||||
#define sfstat_t struct stat
|
||||
#define sysclosef close
|
||||
#define syscreatf creat
|
||||
#define sysdupf dup
|
||||
#define sysfcntlf fcntl
|
||||
#define sysfstatf fstat
|
||||
#define sysftruncatef ftruncate
|
||||
#define syslseekf lseek
|
||||
#define sysmmapf mmap
|
||||
#define sysmunmapf munmap
|
||||
#define sysopenf open
|
||||
#define syspipef pipe
|
||||
#define sysreadf read
|
||||
#define sysremovef remove
|
||||
#define sysstatf stat
|
||||
#define syswritef write
|
||||
|
||||
#else /*!_PACKAGE_ast*/
|
||||
|
||||
/* when building the binary compatibility package, a number of header files
|
||||
|
|
@ -187,28 +153,9 @@
|
|||
#endif /*_FIOCLEX*/
|
||||
#endif /*F_SETFD*/
|
||||
|
||||
#if _hdr_unistd
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !_LARGEFILE64_SOURCE /* turn off the *64 stuff */
|
||||
#undef _typ_off64_t
|
||||
#undef _typ_struct_stat64
|
||||
#undef _lib_creat64
|
||||
#undef _lib_open64
|
||||
#undef _lib_close64
|
||||
#undef _lib_stat64
|
||||
#undef _lib_fstat64
|
||||
#undef _lib_ftruncate64
|
||||
#undef _lib_lseek64
|
||||
#undef _lib_mmap64
|
||||
#undef _lib_munmap64
|
||||
#endif /*!_LARGEFILE64_SOURCE */
|
||||
|
||||
/* see if we can use memory mapping for io */
|
||||
#if _LARGEFILE64_SOURCE && !_lib_mmap64
|
||||
#undef _mmap_worthy
|
||||
#endif
|
||||
#if !_mmap_worthy
|
||||
#undef _hdr_mman
|
||||
#undef _sys_mman
|
||||
|
|
@ -220,76 +167,9 @@
|
|||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/* standardize system calls and types dealing with files */
|
||||
#if _typ_off64_t
|
||||
#define sfoff_t off64_t
|
||||
#else
|
||||
#define sfoff_t off_t
|
||||
#if !_lib_remove
|
||||
#define remove unlink
|
||||
#endif
|
||||
#if _typ_struct_stat64
|
||||
#define sfstat_t struct stat64
|
||||
#else
|
||||
#define sfstat_t struct stat
|
||||
#endif
|
||||
#if _lib_lseek64
|
||||
#define syslseekf lseek64
|
||||
#else
|
||||
#define syslseekf lseek
|
||||
#endif
|
||||
#if _lib_stat64
|
||||
#define sysstatf stat64
|
||||
#else
|
||||
#define sysstatf stat
|
||||
#endif
|
||||
#if _lib_fstat64
|
||||
#define sysfstatf fstat64
|
||||
#else
|
||||
#define sysfstatf fstat
|
||||
#endif
|
||||
#if _lib_mmap64
|
||||
#define sysmmapf mmap64
|
||||
#else
|
||||
#define sysmmapf mmap
|
||||
#endif
|
||||
#if _lib_munmap64
|
||||
#define sysmunmapf munmap64
|
||||
#else
|
||||
#define sysmunmapf munmap
|
||||
#endif
|
||||
#if _lib_open64
|
||||
#define sysopenf open64
|
||||
#else
|
||||
#define sysopenf open
|
||||
#endif
|
||||
#if _lib_creat64
|
||||
#define syscreatf creat64
|
||||
#else
|
||||
#define syscreatf creat
|
||||
#endif
|
||||
#if _lib_close64
|
||||
#define sysclosef close64
|
||||
#else
|
||||
#define sysclosef close
|
||||
#endif
|
||||
#if _lib_ftruncate64
|
||||
#undef _lib_ftruncate
|
||||
#define _lib_ftruncate 1
|
||||
#define sysftruncatef ftruncate64
|
||||
#endif
|
||||
#if !_lib_ftruncate64 && _lib_ftruncate
|
||||
#define sysftruncatef ftruncate
|
||||
#endif
|
||||
#if _lib_remove
|
||||
#define sysremovef remove
|
||||
#else
|
||||
#define sysremovef unlink
|
||||
#endif
|
||||
|
||||
#define sysreadf read
|
||||
#define syswritef write
|
||||
#define syspipef pipe
|
||||
#define sysdupf dup
|
||||
#define sysfcntlf fcntl
|
||||
|
||||
#endif /*_PACKAGE_ast*/
|
||||
|
||||
|
|
@ -553,7 +433,7 @@
|
|||
|
||||
#define SECOND 1000 /* millisecond units */
|
||||
|
||||
/* macros do determine stream types from sfstat_t data */
|
||||
/* macros do determine stream types from 'struct stat' data */
|
||||
#ifndef S_IFDIR
|
||||
#define S_IFDIR 0
|
||||
#endif
|
||||
|
|
@ -851,12 +731,12 @@ typedef struct _sfextern_s
|
|||
#define SFMMSEQOFF(f,a,s)
|
||||
#endif
|
||||
|
||||
#define SFMUNMAP(f,a,s) (sysmunmapf((caddr_t)(a),(size_t)(s)), \
|
||||
#define SFMUNMAP(f,a,s) (munmap((caddr_t)(a),(size_t)(s)), \
|
||||
((f)->endb = (f)->endr = (f)->endw = (f)->next = \
|
||||
(f)->data = NIL(uchar*)) )
|
||||
|
||||
/* safe closing function */
|
||||
#define CLOSE(f) { while(sysclosef(f) < 0 && errno == EINTR) errno = 0; }
|
||||
#define CLOSE(f) { while(close(f) < 0 && errno == EINTR) errno = 0; }
|
||||
|
||||
/* the bottomless bit bucket */
|
||||
#define DEVNULL "/dev/null"
|
||||
|
|
@ -1206,33 +1086,6 @@ extern Sfdouble_t ldexpl(Sfdouble_t, int);
|
|||
|
||||
#if !_PACKAGE_ast
|
||||
|
||||
#if !_hdr_unistd
|
||||
extern int sysclosef(int);
|
||||
extern ssize_t sysreadf(int, void*, size_t);
|
||||
extern ssize_t syswritef(int, const void*, size_t);
|
||||
extern sfoff_t syslseekf(int, sfoff_t, int);
|
||||
extern int sysdupf(int);
|
||||
extern int syspipef(int*);
|
||||
extern int sysaccessf(const char*, int);
|
||||
extern int sysremovef(const char*);
|
||||
extern int sysfstatf(int, sfstat_t*);
|
||||
extern int sysstatf(const char*, sfstat_t*);
|
||||
|
||||
extern int isatty(int);
|
||||
|
||||
extern int wait(int*);
|
||||
extern uint sleep(uint);
|
||||
extern int execl(const char*, const char*,...);
|
||||
extern int execv(const char*, char**);
|
||||
#if !defined(fork)
|
||||
extern int fork(void);
|
||||
#endif
|
||||
#if _lib_unlink
|
||||
extern int unlink(const char*);
|
||||
#endif
|
||||
|
||||
#endif /*_hdr_unistd*/
|
||||
|
||||
#if _lib_bcopy && !_proto_bcopy
|
||||
extern void bcopy(const void*, void*, size_t);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ ssize_t sfpkrd(int fd, /* file descriptor */
|
|||
reg char *buf = (char*)argbuf, *endbuf;
|
||||
|
||||
if(rc < 0 && tm < 0 && action <= 0)
|
||||
return sysreadf(fd,buf,n);
|
||||
return read(fd,buf,n);
|
||||
|
||||
t = (action > 0 || rc >= 0) ? (STREAM_PEEK|SOCKET_PEEK) : 0;
|
||||
#if !_stream_peek
|
||||
|
|
@ -94,7 +94,7 @@ ssize_t sfpkrd(int fd, /* file descriptor */
|
|||
{ t &= ~SOCKET_PEEK;
|
||||
if(r > 0 && (r = pbuf.databuf.len) <= 0)
|
||||
{ if(action <= 0) /* read past eof */
|
||||
r = sysreadf(fd,buf,1);
|
||||
r = read(fd,buf,1);
|
||||
return r;
|
||||
}
|
||||
if(r == 0)
|
||||
|
|
@ -151,7 +151,7 @@ ssize_t sfpkrd(int fd, /* file descriptor */
|
|||
|
||||
if(r > 0) /* there is data now */
|
||||
{ if(action <= 0 && rc < 0)
|
||||
return sysreadf(fd,buf,n);
|
||||
return read(fd,buf,n);
|
||||
else r = -1;
|
||||
}
|
||||
else if(tm >= 0) /* timeout exceeded */
|
||||
|
|
@ -176,7 +176,7 @@ ssize_t sfpkrd(int fd, /* file descriptor */
|
|||
break;
|
||||
else /* read past eof */
|
||||
{ if(action <= 0)
|
||||
r = sysreadf(fd,buf,1);
|
||||
r = read(fd,buf,1);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ ssize_t sfpkrd(int fd, /* file descriptor */
|
|||
if((action = action ? -action : 1) > (int)n)
|
||||
action = n;
|
||||
r = 0;
|
||||
while((t = sysreadf(fd,buf,action)) > 0)
|
||||
while((t = read(fd,buf,action)) > 0)
|
||||
{ r += t;
|
||||
for(endbuf = buf+t; buf < endbuf;)
|
||||
if(*buf++ == rc)
|
||||
|
|
@ -218,7 +218,7 @@ ssize_t sfpkrd(int fd, /* file descriptor */
|
|||
|
||||
/* advance */
|
||||
if(action <= 0)
|
||||
r = sysreadf(fd,buf,r);
|
||||
r = read(fd,buf,r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,9 +192,9 @@ Sfio_t* sfpopen(Sfio_t* f,
|
|||
/* make pipes */
|
||||
parent[0] = parent[1] = child[0] = child[1] = -1;
|
||||
if(sflags&SF_RDWR)
|
||||
{ if(syspipef(parent) < 0)
|
||||
{ if(pipe(parent) < 0)
|
||||
goto error;
|
||||
if((sflags&SF_RDWR) == SF_RDWR && syspipef(child) < 0)
|
||||
if((sflags&SF_RDWR) == SF_RDWR && pipe(child) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ Sfio_t* sfpopen(Sfio_t* f,
|
|||
|
||||
/* must be careful so not to close something useful */
|
||||
if((sflags&SF_RDWR) == SF_RDWR && pkeep == child[ckeep])
|
||||
if((child[ckeep] = sysdupf(pkeep)) < 0)
|
||||
if((child[ckeep] = dup(pkeep)) < 0)
|
||||
_exit(EXIT_NOTFOUND);
|
||||
|
||||
if(sflags&SF_RDWR)
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc)
|
|||
#ifdef MAP_TYPE
|
||||
if(f->bits&SF_MMAP)
|
||||
{ reg ssize_t a, round;
|
||||
sfstat_t st;
|
||||
struct stat st;
|
||||
|
||||
/* determine if we have to copy data to buffer */
|
||||
if((uchar*)buf >= f->data && (uchar*)buf <= f->endb)
|
||||
|
|
@ -140,7 +140,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc)
|
|||
|
||||
/* before mapping, make sure we have data to map */
|
||||
if((f->flags&SF_SHARE) || (size_t)(r = f->extent-f->here) < n)
|
||||
{ if((r = sysfstatf(f->file,&st)) < 0)
|
||||
{ if((r = fstat(f->file,&st)) < 0)
|
||||
goto do_except;
|
||||
if((r = (f->extent = st.st_size) - f->here) <= 0 )
|
||||
{ r = 0; /* eof */
|
||||
|
|
@ -162,10 +162,10 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc)
|
|||
SFMUNMAP(f, f->data, f->endb-f->data);
|
||||
|
||||
for(;;)
|
||||
{ f->data = (uchar*) sysmmapf((caddr_t)0, (size_t)r,
|
||||
{ f->data = (uchar*) mmap((caddr_t)0, (size_t)r,
|
||||
(PROT_READ|PROT_WRITE),
|
||||
MAP_PRIVATE,
|
||||
f->file, (sfoff_t)f->here);
|
||||
f->file, (off_t)f->here);
|
||||
if(f->data && (caddr_t)f->data != (caddr_t)(-1))
|
||||
break;
|
||||
else
|
||||
|
|
@ -259,7 +259,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc)
|
|||
else f->mode |= SF_RC;
|
||||
}
|
||||
}
|
||||
else r = sysreadf(f->file,buf,n);
|
||||
else r = read(f->file,buf,n);
|
||||
|
||||
if(errno == 0 )
|
||||
errno = oerrno;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */
|
|||
{ /* actually read the data now */
|
||||
f->mode &= ~SF_PKRD;
|
||||
if(n > 0)
|
||||
n = (r = sysreadf(f->file,f->data,n)) < 0 ? 0 : r;
|
||||
n = (r = read(f->file,f->data,n)) < 0 ? 0 : r;
|
||||
f->endb = f->data+n;
|
||||
f->here += n;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ int sfresize(Sfio_t* f, Sfoff_t size)
|
|||
{ if(f->next > f->data)
|
||||
SFSYNC(f);
|
||||
#if _lib_ftruncate
|
||||
if(ftruncate(f->file, (sfoff_t)size) < 0)
|
||||
if(ftruncate(f->file, (off_t)size) < 0)
|
||||
SFMTXRETURN(f, -1);
|
||||
#else
|
||||
SFMTXRETURN(f, -1);
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ struct stat
|
|||
{ int st_mode;
|
||||
int st_size;
|
||||
};
|
||||
#undef sysfstatf
|
||||
#define sysfstatf(fd,st) (-1)
|
||||
#undef fstat
|
||||
#define fstat(fd,st) (-1)
|
||||
#endif /*_sys_stat*/
|
||||
|
||||
#if _PACKAGE_ast && !defined(SFSETLINEMODE)
|
||||
|
|
@ -107,7 +107,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */
|
|||
int sf_malloc, oflags, init, okmmap, local;
|
||||
ssize_t bufsize, blksz;
|
||||
Sfdisc_t* disc;
|
||||
sfstat_t st;
|
||||
struct stat st;
|
||||
uchar* obuf = NIL(uchar*);
|
||||
ssize_t osize = 0;
|
||||
SFMTXDECL(f);
|
||||
|
|
@ -227,7 +227,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */
|
|||
}
|
||||
|
||||
/* get file descriptor status */
|
||||
if(sysfstatf((int)f->file,&st) < 0)
|
||||
if(fstat((int)f->file,&st) < 0)
|
||||
f->here = -1;
|
||||
else
|
||||
{
|
||||
|
|
@ -243,7 +243,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */
|
|||
|
||||
#if O_TEXT /* no memory mapping with O_TEXT because read()/write() alter data stream */
|
||||
if(okmmap && f->here >= 0 &&
|
||||
(sysfcntlf((int)f->file,F_GETFL,0) & O_TEXT) )
|
||||
(fcntl((int)f->file,F_GETFL,0) & O_TEXT) )
|
||||
okmmap = 0;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -291,7 +291,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */
|
|||
dev = (int)st.st_dev;
|
||||
ino = (int)st.st_ino;
|
||||
if(!null_checked)
|
||||
{ if(sysstatf(DEVNULL,&st) < 0)
|
||||
{ if(stat(DEVNULL,&st) < 0)
|
||||
null_checked = -1;
|
||||
else
|
||||
{ null_checked = 1;
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ static int _sfdup(int fd, int newfd)
|
|||
reg int dupfd;
|
||||
|
||||
#ifdef F_DUPFD /* the simple case */
|
||||
while((dupfd = sysfcntlf(fd,F_DUPFD,newfd)) < 0 && errno == EINTR)
|
||||
while((dupfd = fcntl(fd,F_DUPFD,newfd)) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
return dupfd;
|
||||
|
||||
#else /* do it the hard way */
|
||||
if((dupfd = sysdupf(fd)) < 0 || dupfd >= newfd)
|
||||
if((dupfd = dup(fd)) < 0 || dupfd >= newfd)
|
||||
return dupfd;
|
||||
|
||||
/* dup() succeeded but didn't get the right number, recurse */
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ Sfoff_t sfsize(Sfio_t* f)
|
|||
}
|
||||
#if _sys_stat
|
||||
else
|
||||
{ sfstat_t st;
|
||||
if(sysfstatf(f->file,&st) < 0)
|
||||
{ struct stat st;
|
||||
if(fstat(f->file,&st) < 0)
|
||||
f->extent = -1;
|
||||
else if((f->extent = st.st_size) < f->here)
|
||||
f->here = SFSK(f,(Sfoff_t)0,SEEK_CUR,disc);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc)
|
|||
{ SFDCSK(f,addr,type,dc,p);
|
||||
}
|
||||
else
|
||||
{ p = syslseekf(f->file,(sfoff_t)addr,type);
|
||||
{ p = lseek(f->file,(off_t)addr,type);
|
||||
}
|
||||
if(p >= 0)
|
||||
SFMTXRETURN(f,p);
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc)
|
|||
(*_Sfnotify)(f,SF_CLOSING,f->file);
|
||||
CLOSE(f->file);
|
||||
f->file = -1;
|
||||
while(sysremovef(ff->name) < 0 && errno == EINTR)
|
||||
while(remove(ff->name) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
|
||||
free((void*)ff);
|
||||
|
|
@ -130,7 +130,7 @@ static int _rmtmp(Sfio_t* f, char* file)
|
|||
(void)vtmtxunlock(_Sfmutex);
|
||||
|
||||
#else /* can remove now */
|
||||
while(sysremovef(file) < 0 && errno == EINTR)
|
||||
while(remove(file) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
#endif
|
||||
|
||||
|
|
@ -253,22 +253,22 @@ static int _tmpfd(Sfio_t* f)
|
|||
if(!file)
|
||||
return -1;
|
||||
#if _has_oflags
|
||||
if((fd = sysopenf(file,O_RDWR|O_CREAT|O_EXCL|O_TEMPORARY,SF_CREATMODE)) >= 0)
|
||||
if((fd = open(file,O_RDWR|O_CREAT|O_EXCL|O_TEMPORARY,SF_CREATMODE)) >= 0)
|
||||
break;
|
||||
#else
|
||||
if((fd = sysopenf(file,O_RDONLY)) >= 0)
|
||||
if((fd = open(file,O_RDONLY)) >= 0)
|
||||
{ /* file already exists */
|
||||
CLOSE(fd);
|
||||
fd = -1;
|
||||
}
|
||||
else if((fd = syscreatf(file,SF_CREATMODE)) >= 0)
|
||||
else if((fd = creat(file,SF_CREATMODE)) >= 0)
|
||||
{ /* reopen for read and write */
|
||||
CLOSE(fd);
|
||||
if((fd = sysopenf(file,O_RDWR)) >= 0)
|
||||
if((fd = open(file,O_RDWR)) >= 0)
|
||||
break;
|
||||
|
||||
/* don't know what happened but must remove file */
|
||||
while(sysremovef(file) < 0 && errno == EINTR)
|
||||
while(remove(file) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
}
|
||||
#endif /* _has_oflags */
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ static ssize_t sfoutput(Sfio_t* f, char* buf, size_t n)
|
|||
{ buf = endbuf;
|
||||
n = s = 0;
|
||||
}
|
||||
if((wr = syswritef(f->file,wbuf,buf-wbuf)) > 0)
|
||||
if((wr = write(f->file,wbuf,buf-wbuf)) > 0)
|
||||
{ w += wr;
|
||||
f->bits &= ~SF_HOLE;
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc)
|
|||
else
|
||||
{
|
||||
do_write:
|
||||
if((w = syswritef(f->file,buf,n)) > 0)
|
||||
if((w = write(f->file,buf,n)) > 0)
|
||||
f->bits &= ~SF_HOLE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */
|
|||
for(w = n; w > 0; )
|
||||
{ if((r = w) > sizeof(buf))
|
||||
r = sizeof(buf);
|
||||
if((r = sysreadf(f->file,buf,r)) <= 0)
|
||||
if((r = read(f->file,buf,r)) <= 0)
|
||||
{ n -= w;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue