Changeset 732


Ignore:
Timestamp:
Sep 26, 2003, 4:41:32 AM (22 years ago)
Author:
bird
Message:

#668: Initial changed related to Large File Support (>2GB).

Location:
trunk/src/emx
Files:
1 added
51 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/Makefile

    • Property cvs2svn:cvs-rev changed from 1.33 to 1.34
    r731 r732  
    7777# The C compiler flags
    7878CFLAGS.INC  += -Iinclude -Isrc/include
    79 CFLAGS      = -Wall -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
     79CFLAGS      = -Wall -Wmissing-prototypes -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
    8080# The additional C compiler flags for different build modes
    8181CFLAGS.opt  = -g -O3
  • trunk/src/emx/bsd/db/include/sys/mman.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r731 r732  
    8383__BEGIN_DECLS
    8484/* Some of these int's should probably be size_t's */
     85#ifndef _MMAP_DECLARED
     86#define _MMAP_DECLARED
    8587caddr_t mmap __P((caddr_t, size_t, int, int, int, off_t));
     88#endif
    8689int     mprotect __P((caddr_t, int, int));
    8790int     munmap __P((caddr_t, int));
  • trunk/src/emx/include/386/_limits.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r731 r732  
    9090
    9191/* bird: our off_t is 32 bit signed at the moment. */
    92 #if 0
     92#if 1
    9393#define __OFF_MAX       __LLONG_MAX     /* max value for an off_t */
    9494#define __OFF_MIN       __LLONG_MIN     /* min value for an off_t */
  • trunk/src/emx/include/386/ansi.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    7575 */
    7676#define _BSD_CT_RUNE_T_ int                     /* arg type for ctype funcs */
    77 #if 0
     77#if 1
    7878#define _BSD_OFF_T_     __int64_t               /* file offset */
    7979#else
  • trunk/src/emx/include/dirent.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r731 r732  
    1 /* dirent.h (emx+gcc) */
     1/*-
     2 * Copyright (c) 1989, 1993
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 * 3. All advertising materials mentioning features or use of this software
     14 *    must display the following acknowledgement:
     15 *      This product includes software developed by the University of
     16 *      California, Berkeley and its contributors.
     17 * 4. Neither the name of the University nor the names of its contributors
     18 *    may be used to endorse or promote products derived from this software
     19 *    without specific prior written permission.
     20 *
     21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31 * SUCH DAMAGE.
     32 *
     33 *      @(#)dirent.h    8.2 (Berkeley) 7/28/94
     34 * $FreeBSD: src/include/dirent.h,v 1.13 2002/09/10 18:12:16 mike Exp $
     35 */
    236
    3 #ifndef _DIRENT_H
    4 #define _DIRENT_H
     37/** @file
     38 * FreeBSD 5.1
     39 * @changes bird: Merged in EMX stuff and internal LIBC stuff.
     40 */
    541
    6 #if !defined (_SYS_TYPES_H)
    7 #warning <dirent.h> requires <sys/types.h>
    8 #include <sys/types.h>
     42#ifndef _DIRENT_H_
     43#define _DIRENT_H_
     44
     45/*
     46 * The kernel defines the format of directory entries returned by
     47 * the getdirentries(2) system call.
     48 */
     49#include <sys/cdefs.h>
     50#include <sys/dirent.h>
     51
     52#if __BSD_VISIBLE || __XSI_VISIBLE
     53/*
     54 * XXX this is probably illegal in the __XSI_VISIBLE case, but brings us closer
     55 * to the specification.
     56 */
     57#define d_ino           d_fileno        /* backward and XSI compatibility */
    958#endif
    1059
    11 #include <sys/dirent.h>
     60#if __BSD_VISIBLE
    1261
    13 #if defined (__cplusplus)
    14 extern "C" {
     62/* definitions for library routines operating on directories. */
     63#define DIRBLKSIZ       1024
     64
     65struct _telldir;                /* see telldir.h */
     66
     67/* bird: EMX internal structure. */
     68struct _dircontents
     69{
     70  struct _dircontents * _d_next;
     71  char *                _d_entry;
     72  __off_t               _d_size;
     73  unsigned short        _d_time;
     74  unsigned short        _d_date;
     75  unsigned short        _d_attr;
     76  unsigned char         _d_type;
     77};
     78
     79/* structure describing an open directory. */
     80typedef struct _dirdesc {
     81#if 0
     82        int     dd_fd;          /* file descriptor associated with directory */
     83        long    dd_loc;         /* offset in current buffer */
     84        long    dd_size;        /* amount of data returned by getdirentries */
     85        char    *dd_buf;        /* data buffer */
     86        int     dd_len;         /* size of data buffer */
     87        long    dd_seek;        /* magic cookie returned by getdirentries */
     88        long    dd_rewind;      /* magic cookie for rewinding */
     89        int     dd_flags;       /* flags for readdir */
     90        void    *dd_lock;       /* hack to avoid including <pthread.h> */
     91        struct _telldir *dd_td; /* telldir position recording */
     92#else
     93        int                   dd_id;
     94        long                  dd_loc;
     95        struct _dircontents * dd_contents;
     96        struct _dircontents * dd_cp;
     97        struct dirent         dd_dirent;
     98#endif
     99} DIR;
     100
     101#define dirfd(dirp)     ((dirp)->dd_fd)
     102
     103/* flags for opendir2 */
     104#define DTF_HIDEW       0x0001  /* hide whiteout entries */
     105#define DTF_NODUP       0x0002  /* don't return duplicate names */
     106#define DTF_REWIND      0x0004  /* rewind after reading union stack */
     107#define __DTF_READALL   0x0008  /* everything has been read */
     108
     109#ifndef NULL
     110#define NULL    0
    15111#endif
    16112
    17 struct _dirdesc;
     113#else /* !__BSD_VISIBLE */
    18114
    19 typedef struct _dirdesc DIR;
     115typedef void *  DIR;
    20116
    21 DIR *opendir (__const__ char *);
    22 struct dirent *readdir (DIR *);
    23 int closedir (DIR *);
    24 void rewinddir (DIR *);
     117#endif /* __BSD_VISIBLE */
    25118
    26 #if !defined (_POSIX_SOURCE)
    27 void seekdir (DIR *, long);
    28 long telldir (DIR *);
     119#ifndef _KERNEL
     120
     121__BEGIN_DECLS
     122#if __BSD_VISIBLE
     123/** @todo DIR   *__opendir2(const char *, int); */
     124/** @todo int    alphasort(const void *, const void *); */
     125/** @todo int    getdents(int, char *, int); */
     126/** @todo int    getdirentries(int, char *, int, long *); */
    29127#endif
     128DIR     *opendir(const char *);
     129struct dirent *
     130         readdir(DIR *);
     131#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500
     132int      readdir_r(DIR *, struct dirent *, struct dirent **);
     133#endif
     134void     rewinddir(DIR *);
     135#if __BSD_VISIBLE
     136int      scandir(const char *, struct dirent ***,
     137            int (*)(struct dirent *), int (*)(const void *, const void *));
     138#endif
     139#if __XSI_VISIBLE
     140void     seekdir(DIR *, long);
     141long     telldir(DIR *);
     142#endif
     143int      closedir(DIR *);
    30144
     145
     146/* bird: EMX extra - start */
    31147DIR *_opendir (__const__ char *);
    32148struct dirent *_readdir (DIR *);
     
    35151int _closedir (DIR *);
    36152void _rewinddir (DIR *);
     153/* bird: EMX extra - end */
    37154
    38 #if defined (__cplusplus)
    39 }
    40 #endif
     155__END_DECLS
    41156
    42 #endif /* not _DIRENT_H */
     157#endif /* !_KERNEL */
     158
     159#endif /* !_DIRENT_H_ */
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    77extern "C" {
    88#endif
     9
     10#include <sys/types.h>
    911
    1012#if !defined (NULL)
     
    1416#define NULL ((void *)0)
    1517#endif
    16 #endif
    17 
    18 #if !defined (_SIZE_T)
    19 #define _SIZE_T
    20 typedef unsigned long size_t;
    2118#endif
    2219
     
    217214void _closestream (struct _FILE *);
    218215int _fflush_nolock (struct _FILE *);
    219 int _fseek_nolock (struct _FILE *, long, int);
    220 long _ftell_nolock (struct _FILE *);
     216int _fseek_nolock (struct _FILE *, off_t, int);
     217off_t _ftell_nolock (struct _FILE *);
    221218size_t _fwrite_nolock (const void *, size_t, size_t, struct _FILE *);
    222219int _input (struct _FILE *, __const__ char *, char *);
  • trunk/src/emx/include/emx/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r731 r732  
    33#ifndef _EMX_SYSCALLS_H
    44#define _EMX_SYSCALLS_H
     5
     6#include <sys/types.h>
    57
    68#if defined (__cplusplus)
     
    3739typedef unsigned long sigset_t;
    3840#endif
    39 
    40 #if !defined (_SIZE_T)
    41 #define _SIZE_T
    42 typedef unsigned long size_t;
    43 #endif
    44 
    4541
    4642struct hostent;
     
    5450struct timeval;
    5551
     52#pragma pack(1)
    5653struct _find
    5754{
    58   char           reserved[21];
    59   unsigned char  attr;
    60   unsigned short time;
    61   unsigned short date;
    62   unsigned short size_lo;         /* split due to alignment problems */
    63   unsigned short size_hi;
    64   char name[257];                 /* Big buffer for OS/2             */
    65 };
     55    /** Size of file, in number of bytes. */
     56    off_t           cbFile;
     57    /** Last written (OS/2 & DOS time). */
     58    unsigned short  time;
     59    /** Last written (OS/2 & DOS date). */
     60    unsigned short  date;
     61    /** File attributes. */
     62    unsigned char   attr;
     63    /** File name */
     64    char            szName[257];
     65};
     66#pragma pack()
    6667
    6768struct _new_proc
     
    128129int __chmod (__const__ char *name, int flag, int attr);
    129130int __chdrive (char drive);
    130 int __chsize (int handle, long length);
     131int __chsize (int handle, off_t length);
    131132long long __clock (void);
    132133int __close (int handle);
     
    146147int __fsync (int handle);
    147148void __ftime (struct timeb *ptr);
    148 int __ftruncate (int handle, long length);
     149int __ftruncate (int handle, off_t length);
    149150int __getcwd (char *buffer, char drive);
    150151char __getdrive (void);
     
    175176int __kill (int pid, int sig);
    176177int __listen (int handle, int backlog);
    177 int __lseek (int handle, long offset, int origin);
     178off_t __lseek (int handle, off_t offset, int origin);
    178179int __memavail (void);
    179180int __mkdir (__const__ char *name);
    180181int __newthread (int tid);
    181 int __open (__const__ char *name, int flags, unsigned long size);
     182int __open (__const__ char *name, int flags, off_t size);
    182183int __pause (void);
    183184int __pipe (int *two_handles, int pipe_size);
  • trunk/src/emx/include/io.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r731 r732  
    4949int access (__const__ char *, int);
    5050int chmod (__const__ char *, int);
    51 int chsize (int, long);
     51int chsize (int, off_t);
    5252int close (int);
    5353int creat (const char *, mode_t);
     
    5555int dup2 (int, int);
    5656int eof (int);
    57 long filelength (int);
     57off_t filelength (int);
    5858int fstat (int, struct stat *);
    5959int fsync (int);
     
    7777int sopen (__const__ char *, int, int, ...);
    7878int stat (__const__ char *, struct stat *);
    79 long tell (int);
     79off_t tell (int);
    8080#ifndef _TRUNCATE_DECLARED
    8181#define _TRUNCATE_DECLARED
     
    9191int _access (__const__ char *, int);
    9292int _chmod (__const__ char *, int);
    93 int _chsize (int, long);
     93int _chsize (int, off_t);
    9494int _close (int);
    9595int _creat (__const__ char *, int);
     
    9898int _dup2 (int, int);
    9999int _eof (int);
    100 long _filelength (int);
     100off_t _filelength (int);
    101101int _fstat (int, struct stat *);
    102102int _fsync (int);
     
    123123int _sopen (__const__ char *, int, int, ...);
    124124int _stat (__const__ char *, struct stat *);
    125 long _tell (int);
    126 int _truncate (char *, long);
     125off_t _tell (int);
     126int _truncate (char *, off_t);
    127127int _umask (int);
    128128int _unlink (__const__ char *);
  • trunk/src/emx/include/os2emx.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r731 r732  
    12681268#define FIL_QUERYEASIZEL                12
    12691269#define FIL_QUERYEASFROMLISTL           13
    1270 #define FIL_QUERYFULLNAME               5 /* DosQueryPathInfo */
     1270#define FIL_QUERYFULLNAME               5
    12711271
    12721272#define FILE_BEGIN                      0
     
    15891589typedef FILEFINDBUF4 *PFILEFINDBUF4;
    15901590
     1591typedef struct _FILEFINDBUF3L
     1592{
     1593    ULONG       oNextEntryOffset;
     1594    FDATE       fdateCreation;
     1595    FTIME       ftimeCreation;
     1596    FDATE       fdateLastAccess;
     1597    FTIME       ftimeLastAccess;
     1598    FDATE       fdateLastWrite;
     1599    FTIME       ftimeLastWrite;
     1600    LONGLONG    cbFile;
     1601    LONGLONG    cbFileAlloc;
     1602    ULONG       attrFile;
     1603    UCHAR       cchName;
     1604    CHAR        achName[CCHMAXPATHCOMP];
     1605} FILEFINDBUF3L;
     1606typedef FILEFINDBUF3L *PFILEFINDBUF3L;
     1607
     1608typedef struct _FILEFINDBUF4L
     1609{
     1610    ULONG       oNextEntryOffset;
     1611    FDATE       fdateCreation;
     1612    FTIME       ftimeCreation;
     1613    FDATE       fdateLastAccess;
     1614    FTIME       ftimeLastAccess;
     1615    FDATE       fdateLastWrite;
     1616    FTIME       ftimeLastWrite;
     1617    LONGLONG    cbFile;
     1618    LONGLONG    cbFileAlloc;
     1619    ULONG       attrFile;
     1620    ULONG       cbList;
     1621    UCHAR       cchName;
     1622    CHAR        achName[CCHMAXPATHCOMP];
     1623} FILEFINDBUF4L;
     1624typedef FILEFINDBUF4L  *PFILEFINDBUF4L;
     1625
    15911626typedef struct _FILELOCK
    15921627{
     
    15961631typedef FILELOCK *PFILELOCK;
    15971632
    1598 typedef struct _FILELOCKL     /* flock */
     1633typedef struct _FILELOCKL
    15991634{
    16001635  LONGLONG lOffset;
  • trunk/src/emx/include/stdio.h

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r731 r732  
    1 /* stdio.h (emx+gcc) */
    2 
    3 #ifndef _STDIO_H
    4 #define _STDIO_H
    5 
    6 #if defined (__cplusplus)
    7 extern "C" {
    8 #endif
     1/*-
     2 * Copyright (c) 1990, 1993
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * This code is derived from software contributed to Berkeley by
     6 * Chris Torek.
     7 *
     8 * Redistribution and use in source and binary forms, with or without
     9 * modification, are permitted provided that the following conditions
     10 * are met:
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. All advertising materials mentioning features or use of this software
     17 *    must display the following acknowledgement:
     18 *      This product includes software developed by the University of
     19 *      California, Berkeley and its contributors.
     20 * 4. Neither the name of the University nor the names of its contributors
     21 *    may be used to endorse or promote products derived from this software
     22 *    without specific prior written permission.
     23 *
     24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34 * SUCH DAMAGE.
     35 *
     36 *      @(#)stdio.h     8.5 (Berkeley) 4/29/95
     37 * $FreeBSD: src/include/stdio.h,v 1.51 2003/01/13 08:41:47 tjr Exp $
     38 */
     39
     40/** @file
     41 * FreeBSD 5.1
     42 * @changed bird: EMX isms + LIBC implementation specifics.
     43 * @chagned bird: Made quite a few @todos on function which aren't implemented.
     44 */
     45
     46#ifndef _STDIO_H_
     47#define _STDIO_H_
    948
    1049#include <sys/cdefs.h>
    1150#include <sys/_types.h>
    1251
    13 #if !defined(_VA_LIST_DECLARED) && !defined(_VA_LIST) /* bird: emx */
     52typedef __off_t         fpos_t;
     53
     54#ifndef _SIZE_T_DECLARED
     55typedef __size_t        size_t;
     56#define _SIZE_T_DECLARED
     57#define _SIZE_T                         /* bird: emx */
     58#endif
     59
     60#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
     61#ifndef _VA_LIST_DECLARED
     62typedef __va_list       va_list;
    1463#define _VA_LIST_DECLARED
    1564#define _VA_LIST                        /* bird: emx */
    16 typedef __va_list       va_list;
    17 #endif
    18 
    19 #if !defined (_SIZE_T)
    20 #define _SIZE_T
    21 typedef unsigned long size_t;
    22 #endif
    23 
    24 #if !defined (NULL)
    25 #if defined (__cplusplus)
    26 #define NULL 0
    27 #else
    28 #define NULL ((void *)0)
    29 #endif
    30 #endif
    31 
    32 #if !defined (BUFSIZ)
    33 #define BUFSIZ 5120
    34 #endif
    35 
    36 #if !defined (_FILE_T)
     65#endif
     66#endif
     67
     68#ifndef NULL
     69#define NULL    0
     70#endif
     71
     72#define _FSTDIO                 /* Define for new stdio with functions. */
     73
     74#if 0                                   /* bird: emx */
     75
     76/*
     77 * NB: to fit things in six character monocase externals, the stdio
     78 * code uses the prefix `__s' for stdio objects, typically followed
     79 * by a three-character attempt at a mnemonic.
     80 */
     81
     82/* stdio buffers */
     83struct __sbuf {
     84        unsigned char *_base;
     85        int     _size;
     86};
     87
     88/* hold a buncha junk that would grow the ABI */
     89struct __sFILEX;
     90
     91/*
     92 * stdio state variables.
     93 *
     94 * The following always hold:
     95 *
     96 *      if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
     97 *              _lbfsize is -_bf._size, else _lbfsize is 0
     98 *      if _flags&__SRD, _w is 0
     99 *      if _flags&__SWR, _r is 0
     100 *
     101 * This ensures that the getc and putc macros (or inline functions) never
     102 * try to write or read from a file that is in `read' or `write' mode.
     103 * (Moreover, they can, and do, automatically switch from read mode to
     104 * write mode, and back, on "r+" and "w+" files.)
     105 *
     106 * _lbfsize is used only to make the inline line-buffered output stream
     107 * code as compact as possible.
     108 *
     109 * _ub, _up, and _ur are used when ungetc() pushes back more characters
     110 * than fit in the current _bf, or when ungetc() pushes back a character
     111 * that does not match the previous one in _bf.  When this happens,
     112 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
     113 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
     114 *
     115 * NB: see WARNING above before changing the layout of this structure!
     116 */
     117typedef struct __sFILE {
     118        unsigned char *_p;      /* current position in (some) buffer */
     119        int     _r;             /* read space left for getc() */
     120        int     _w;             /* write space left for putc() */
     121        short   _flags;         /* flags, below; this FILE is free if 0 */
     122        short   _file;          /* fileno, if Unix descriptor, else -1 */
     123        struct  __sbuf _bf;     /* the buffer (at least 1 byte, if !NULL) */
     124        int     _lbfsize;       /* 0 or -_bf._size, for inline putc */
     125
     126        /* operations */
     127        void    *_cookie;       /* cookie passed to io functions */
     128        int     (*_close)(void *);
     129        int     (*_read)(void *, char *, int);
     130        fpos_t  (*_seek)(void *, fpos_t, int);
     131        int     (*_write)(void *, const char *, int);
     132
     133        /* separate buffer for long sequences of ungetc() */
     134        struct  __sbuf _ub;     /* ungetc buffer */
     135        struct __sFILEX *_extra; /* additions to FILE to not break ABI */
     136        int     _ur;            /* saved _r when _r is counting ungetc data */
     137
     138        /* tricks to meet minimum requirements even when malloc() fails */
     139        unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
     140        unsigned char _nbuf[1]; /* guarantee a getc() buffer */
     141
     142        /* separate buffer for fgetln() when line crosses buffer boundary */
     143        struct  __sbuf _lb;     /* buffer for fgetln() */
     144
     145        /* Unix stdio files get aligned to block boundaries on fseek() */
     146        int     _blksize;       /* stat.st_blksize (may be != _bf._size) */
     147        fpos_t  _offset;        /* current lseek offset (see WARNING) */
     148} FILE;
     149
     150__BEGIN_DECLS
     151extern FILE *__stdinp;
     152extern FILE *__stdoutp;
     153extern FILE *__stderrp;
     154__END_DECLS
     155
     156#define __SLBF  0x0001          /* line buffered */
     157#define __SNBF  0x0002          /* unbuffered */
     158#define __SRD   0x0004          /* OK to read */
     159#define __SWR   0x0008          /* OK to write */
     160        /* RD and WR are never simultaneously asserted */
     161#define __SRW   0x0010          /* open for reading & writing */
     162#define __SEOF  0x0020          /* found EOF */
     163#define __SERR  0x0040          /* found error */
     164#define __SMBF  0x0080          /* _buf is from malloc */
     165#define __SAPP  0x0100          /* fdopen()ed in append mode */
     166#define __SSTR  0x0200          /* this is an sprintf/snprintf string */
     167#define __SOPT  0x0400          /* do fseek() optimization */
     168#define __SNPT  0x0800          /* do not do fseek() optimization */
     169#define __SOFF  0x1000          /* set iff _offset is in fact correct */
     170#define __SMOD  0x2000          /* true => fgetln modified _p text */
     171#define __SALC  0x4000          /* allocate string space dynamically */
     172#define __SIGN  0x8000          /* ignore this file in _fwalk */
     173
     174#else  /* bird: EMX specific FILE stuff starts. */
     175
    37176#define _FILE_T
    38177#define _FILE_MEMBERS_HAVE_UNDERSCORE
    39178struct _file2;
    40 struct _FILE
     179typedef struct _FILE
    41180{
    42181  char * _ptr;
     
    54193  int    (*_flush)(struct _FILE *, int);
    55194  struct _file2 *_more;
    56 };
    57 
    58 typedef struct _FILE FILE;
    59 
     195} FILE;
     196
     197__BEGIN_DECLS
    60198extern FILE _streamv[];
    61 
    62 #define stdin  (&_streamv[0])
    63 #define stdout (&_streamv[1])
    64 #define stderr (&_streamv[2])
    65 
    66 #endif
    67 
    68 #if !defined (SEEK_SET)
    69 #define SEEK_SET 0
    70 #define SEEK_CUR 1
    71 #define SEEK_END 2
    72 #endif
    73 
    74 #if !defined (EOF)
    75 #define EOF (-1)
    76 #endif
     199__END_DECLS
     200
     201#define __stdinp    (&_streamv[0])
     202#define __stdoutp   (&_streamv[1])
     203#define __stderrp   (&_streamv[2])
     204
     205#endif /* bird: EMX specific FILE stuff ends. */
     206
     207
     208/*
     209 * The following three definitions are for ANSI C, which took them
     210 * from System V, which brilliantly took internal interface macros and
     211 * made them official arguments to setvbuf(), without renaming them.
     212 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
     213 *
     214 * Although numbered as their counterparts above, the implementation
     215 * does not rely on this.
     216 */
     217#define _IOFBF  0               /* setvbuf should set fully buffered */
     218#define _IOLBF  0x20 /* bird: emx, was 1 */ /* setvbuf should set line buffered */
     219#define _IONBF  0x40 /* bird: emx, was 2 */ /* setvbuf should set unbuffered */
     220
     221#define BUFSIZ  5120 /* bird: emx, was 1024 */ /* size of buffer used by setbuf */
     222#define EOF     (-1)
     223
     224/*
     225 * FOPEN_MAX is a minimum maximum, and is the number of streams that
     226 * stdio can provide without attempting to allocate further resources
     227 * (which could fail).  Do not use this for anything.
     228 */
     229                                /* must be == _POSIX_STREAM_MAX <limits.h> */
     230#define FOPEN_MAX       14   /* bird: emx, was 20 */ /* must be <= OPEN_MAX <sys/syslimits.h> */
     231#define FILENAME_MAX    260  /* bird: emx, was 1024 */ /* must be <= PATH_MAX <sys/syslimits.h> */
     232
     233/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
     234#if __XSI_VISIBLE
     235#define P_tmpdir        "." /* bird: emx, was "/var/tmp/" */
     236#endif
     237#define L_tmpnam        260  /* bird: emx, was 1024 */ /* XXX must be == PATH_MAX */
     238#define TMP_MAX         1000 /* bird: emx, was 308915776 */
     239
     240#ifndef SEEK_SET
     241#define SEEK_SET        0       /* set file offset to offset */
     242#endif
     243#ifndef SEEK_CUR
     244#define SEEK_CUR        1       /* set file offset to current plus offset */
     245#endif
     246#ifndef SEEK_END
     247#define SEEK_END        2       /* set file offset to EOF plus offset */
     248#endif
     249
     250#define stdin   __stdinp
     251#define stdout  __stdoutp
     252#define stderr  __stderrp
     253
     254__BEGIN_DECLS
     255/*
     256 * Functions defined in ANSI C standard.
     257 */
     258void     clearerr(FILE *);
     259int      fclose(FILE *);
     260int      feof(FILE *);
     261int      ferror(FILE *);
     262int      fflush(FILE *);
     263int      fgetc(FILE *);
     264int      fgetpos(FILE * __restrict, fpos_t * __restrict);
     265char    *fgets(char * __restrict, int, FILE * __restrict);
     266FILE    *fopen(const char * __restrict, const char * __restrict);
     267int      fprintf(FILE * __restrict, const char * __restrict, ...);
     268int      fputc(int, FILE *);
     269int      fputs(const char * __restrict, FILE * __restrict);
     270size_t   fread(void * __restrict, size_t, size_t, FILE * __restrict);
     271FILE    *freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
     272int      fscanf(FILE * __restrict, const char * __restrict, ...);
     273int      fseek(FILE *, long, int);
     274int      fsetpos(FILE *, const fpos_t *);
     275long     ftell(FILE *);
     276size_t   fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
     277#if 0                                   /* bird: emx */
     278int      getc(FILE *);
     279#else                                   /* bird: emx */
     280/** @todo: Check the standard, if this is correct or not. declaration might be required. */
     281#define getc(s)   fgetc(s)              /* bird: emx */
     282#endif                                  /* bird: emx */
     283int      getchar(void);
     284char    *gets(char *);
     285void     perror(const char *);
     286int      printf(const char * __restrict, ...);
     287#if 0                                   /* bird: emx */
     288int      putc(int, FILE *);
     289#else                                   /* bird: emx */
     290/** @todo: Check the standard, if this is correct or not. declaration might be required. */
     291#define putc(c,s) fputc(c,s)            /* bird: emx */
     292#endif                                  /* bird: emx */
     293int      putchar(int);
     294int      puts(const char *);
     295int      remove(const char *);
     296int      rename(const char *, const char *);
     297void     rewind(FILE *);
     298int      scanf(const char * __restrict, ...);
     299void     setbuf(FILE * __restrict, char * __restrict);
     300int      setvbuf(FILE * __restrict, char * __restrict, int, size_t);
     301int      sprintf(char * __restrict, const char * __restrict, ...);
     302int      sscanf(const char * __restrict, const char * __restrict, ...);
     303FILE    *tmpfile(void);
     304char    *tmpnam(char *);
     305int      ungetc(int, FILE *);
     306int      vfprintf(FILE * __restrict, const char * __restrict,
     307            __va_list);
     308int      vprintf(const char * __restrict, __va_list);
     309int      vsprintf(char * __restrict, const char * __restrict,
     310            __va_list);
     311
     312#if __ISO_C_VISIBLE >= 1999
     313int      snprintf(char * __restrict, size_t, const char * __restrict,
     314            ...) __printflike(3, 4);
     315int      vfscanf(FILE * __restrict, const char * __restrict, __va_list)
     316            __scanflike(2, 0);
     317int      vscanf(const char * __restrict, __va_list) __scanflike(1, 0);
     318int      vsnprintf(char * __restrict, size_t, const char * __restrict,
     319            __va_list) __printflike(3, 0);
     320int      vsscanf(const char * __restrict, const char * __restrict, __va_list)
     321            __scanflike(2, 0);
     322#endif
     323
     324/*
     325 * Functions defined in all versions of POSIX 1003.1.
     326 */
     327#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
     328/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
     329#define L_cuserid       9 /* bird: emx, was 17 */ /* legacy */
     330#endif
     331
     332#if __POSIX_VISIBLE
     333#define L_ctermid       260 /* bird: emx, was 1024 */ /* size for ctermid(3); PATH_MAX */
     334
     335/** @todo char  *ctermid(char *); */
     336FILE    *fdopen(int, const char *);
     337int      fileno(FILE *);
     338#endif /* __POSIX_VISIBLE */
     339
     340#if __POSIX_VISIBLE >= 199209
     341int      pclose(FILE *);
     342FILE    *popen(const char *, const char *);
     343#endif
     344
     345#if __POSIX_VISIBLE >= 199506
     346/** @todo int    ftrylockfile(FILE *); */
     347/** @todo void   flockfile(FILE *); */
     348/** @todo void   funlockfile(FILE *); */
     349
     350/*
     351 * These are normally used through macros as defined below, but POSIX
     352 * requires functions as well.
     353 */
     354/** @todo int    getc_unlocked(FILE *); */
     355/** @todo int    getchar_unlocked(void); */
     356/** @todo int    putc_unlocked(int, FILE *); */
     357/** @todo int    putchar_unlocked(int); */
     358#endif
     359#if __BSD_VISIBLE
     360/** @todo void  clearerr_unlocked(FILE *); */
     361/** @todo int   feof_unlocked(FILE *); */
     362/** @todo int   ferror_unlocked(FILE *); */
     363/** @todo int   fileno_unlocked(FILE *); */
     364#endif
     365
     366#if __POSIX_VISIBLE >= 200112
     367int      fseeko(FILE *, __off_t, int);
     368__off_t  ftello(FILE *);
     369#endif
     370
     371#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
     372int      getw(FILE *);
     373int      putw(int, FILE *);
     374#endif /* BSD or X/Open before issue 6 */
     375
     376#if __XSI_VISIBLE
     377char    *tempnam(const char *, const char *);
     378#endif
     379
     380/*
     381 * Routines that are purely local.
     382 */
     383#if __BSD_VISIBLE
     384/** @todo int    asprintf(char **, const char *, ...) __printflike(2, 3); */
     385/** @todo char  *ctermid_r(char *); */
     386/** @todo char  *fgetln(FILE *, size_t *); */
     387#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3
     388#define __ATTR_FORMAT_ARG       __attribute__((__format_arg__(2)))
     389#else
     390#define __ATTR_FORMAT_ARG
     391#endif
     392/** @todo __const char *fmtcheck(const char *, const char *) __ATTR_FORMAT_ARG; */
     393/** @todo int    fpurge(FILE *); */
     394void     setbuffer(FILE *, char *, int);
     395/** @todo int    setlinebuf(FILE *); */
     396/** @todo int    vasprintf(char **, const char *, __va_list)
     397            __printflike(2, 0); */
     398
     399/*
     400 * The system error table contains messages for the first sys_nerr
     401 * positive errno values.  Use strerror() or strerror_r() from <string.h>
     402 * instead.
     403 */
     404extern __const int sys_nerr;
     405extern __const char *__const sys_errlist[];
     406
     407/*
     408 * Stdio function-access interface.
     409 */
     410/** @todo FILE  *funopen(const void *,
     411            int (*)(void *, char *, int),
     412            int (*)(void *, const char *, int),
     413            fpos_t (*)(void *, fpos_t, int),
     414            int (*)(void *)); */
     415/** @todo #define       fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) */
     416/** @todo #define       fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) */
     417
     418/*
     419 * Portability hacks.  See <sys/types.h>.
     420 */
     421#ifndef _FTRUNCATE_DECLARED
     422#define _FTRUNCATE_DECLARED
     423int      ftruncate(int, __off_t);
     424#endif
     425#ifndef _LSEEK_DECLARED
     426#define _LSEEK_DECLARED
     427__off_t  lseek(int, __off_t, int);
     428#endif
     429#ifndef _MMAP_DECLARED
     430#define _MMAP_DECLARED
     431void    *mmap(void *, size_t, int, int, int, __off_t);
     432#endif
     433#ifndef _TRUNCATE_DECLARED
     434#define _TRUNCATE_DECLARED
     435int      truncate(const char *, __off_t);
     436#endif
     437#endif /* __BSD_VISIBLE */
     438
     439#if 0 /* bird: Skip FreeBSD sepcific LIBC stuff. */
     440/*
     441 * Functions internal to the implementation.
     442 */
     443int     __srget(FILE *);
     444int     __swbuf(int, FILE *);
     445
     446/*
     447 * The __sfoo macros are here so that we can
     448 * define function versions in the C library.
     449 */
     450#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
     451#if defined(__GNUC__) && defined(__STDC__)
     452static __inline int __sputc(int _c, FILE *_p) {
     453        if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
     454                return (*_p->_p++ = _c);
     455        else
     456                return (__swbuf(_c, _p));
     457}
     458#else
     459/*
     460 * This has been tuned to generate reasonable code on the vax using pcc.
     461 */
     462#define __sputc(c, p) \
     463        (--(p)->_w < 0 ? \
     464                (p)->_w >= (p)->_lbfsize ? \
     465                        (*(p)->_p = (c)), *(p)->_p != '\n' ? \
     466                                (int)*(p)->_p++ : \
     467                                __swbuf('\n', p) : \
     468                        __swbuf((int)(c), p) : \
     469                (*(p)->_p = (c), (int)*(p)->_p++))
     470#endif
     471
     472#define __sfeof(p)      (((p)->_flags & __SEOF) != 0)
     473#define __sferror(p)    (((p)->_flags & __SERR) != 0)
     474#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
     475#define __sfileno(p)    ((p)->_file)
     476
     477#if __BSD_VISIBLE
     478/*
     479 * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
     480 * B.8.2.7 for the rationale behind the *_unlocked() macros.
     481 */
     482#define feof_unlocked(p)        __sfeof(p)
     483#define ferror_unlocked(p)      __sferror(p)
     484#define clearerr_unlocked(p)    __sclearerr(p)
     485#define fileno_unlocked(p)      __sfileno(p)
     486#endif
     487#if __POSIX_VISIBLE >= 199506
     488#define getc_unlocked(fp)       __sgetc(fp)
     489#define putc_unlocked(x, fp)    __sputc(x, fp)
     490
     491#define getchar_unlocked()      getc_unlocked(stdin)
     492#define putchar_unlocked(x)     putc_unlocked(x, stdout)
     493#endif
     494
     495#endif /* bird: Skip FreeBSD sepcific LIBC stuff. */
     496
     497
     498/* bird: start of EMX isms. */
    77499
    78500#if !defined (_IOREAD)
     501/** @todo change to double underscore prefix to prevent confusion with
     502 * setvbuf() constants. See the short rant about it above. */
    79503#define _IOREAD 0x01
    80504#define _IOWRT  0x02
     
    82506#define _IOEOF  0x08
    83507#define _IOERR  0x10
    84 #define _IOFBF  0x00
    85 #define _IOLBF  0x20
    86 #define _IONBF  0x40
    87 #endif
    88 
    89 #if !defined (FOPEN_MAX)
    90 #define FOPEN_MAX       14
    91 #endif
    92 
    93 #if !defined (FILENAME_MAX)
    94 #define FILENAME_MAX    260
    95 #endif
    96 
    97 #if !defined (TMP_MAX)
    98 #define TMP_MAX         1000
    99 #endif
    100 
    101 #if !defined (P_tmpdir)
    102 #define P_tmpdir "."
    103 #define L_tmpnam (sizeof (P_tmpdir) + 13)
    104 #endif
    105 
    106 #if !defined (L_cuserid)
    107 #define L_cuserid       9
    108 #endif
    109 
    110 #if !defined (_FPOS_T)
    111 #define _FPOS_T
    112 typedef struct
    113 {
    114   long _pos;
    115   long _reserved1;
    116   short _mbstate;
    117   short _reserved2;
    118 } fpos_t;
    119 #endif
    120 
    121 
    122 void clearerr (FILE *);
    123 int fclose (FILE *);
    124 int feof (FILE *);
    125 int ferror (FILE *);
    126 int fflush (FILE *);
    127 int fgetc (FILE *);
    128 int fgetpos (FILE *, fpos_t *);
    129 char *fgets (char *, int, FILE *);
    130 FILE *fopen (__const__ char *, __const__ char *);
    131 int fprintf (FILE *, __const__ char *, ...);
    132 int fputc (int, FILE *);
    133 int fputs (__const__ char *, FILE *);
    134 size_t fread (void *, size_t, size_t, FILE *);
    135 FILE *freopen (__const__ char *, __const__ char *, FILE *);
    136 int fscanf (FILE *, __const__ char *, ...);
    137 int fseek (FILE *, long, int);
    138 int fsetpos (FILE *, __const__ fpos_t *);
    139 long ftell (FILE *);
    140 size_t fwrite (__const__ void *, size_t, size_t, FILE *);
    141 int getchar (void);
    142 char *gets (char *);
    143 void perror (__const__ char *);
    144 int printf (__const__ char *, ...);
    145 int putchar (int);
    146 int puts (__const__ char *);
    147 int remove (__const__ char *);
    148 int rename (__const__ char *, __const__ char *);
    149 void rewind (FILE *);
    150 int scanf (__const__ char *, ...);
    151 int setbuf (FILE *, char *);
    152 int setvbuf (FILE *, char *, int, size_t);
    153 int sprintf (char *, __const__ char *, ...);
    154 int sscanf (__const__ char *, __const__ char *, ...);
    155 FILE *tmpfile (void);
    156 char *tmpnam (char *);
    157 int ungetc (int, FILE *);
    158 int vfprintf (FILE *, __const__ char *, va_list);
    159 int vprintf (__const__ char *, va_list);
    160 int vsprintf (char *, __const__ char *, va_list);
     508#endif
    161509
    162510int _fill (FILE *);
     
    174522}
    175523
    176 #define getc(s)   fgetc(s)
    177 #define putc(c,s) fputc(c,s)
    178 
    179524extern __inline__ int getchar (void) { return getc (stdin); }
    180525extern __inline__ int putchar (int _c) { return putc (_c, stdout); }
    181526
    182 
    183 #if !defined (__STRICT_ANSI__)
    184 
    185 /* POSIX.1 */
    186 
    187 /* ctermid() */
    188 FILE *fdopen (int, __const__ char *);
    189 int fileno (FILE *);
    190 
    191 extern __inline__ int fileno (FILE *_s) { return _s->_handle; }
    192 
    193 #endif
    194 
    195 
    196527#if !defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)
    197528
    198529char *cuserid (char *);
    199 int getw (FILE *);
    200530int fcloseall (void);
    201531int fgetchar (void);
    202532int flushall (void);
    203533int fputchar (int);
    204 int pclose (FILE *);
    205 FILE *popen (__const__ char *, __const__ char *);
    206 int putw (int, FILE *);
    207 int setbuffer (FILE *, char *, size_t);
    208 int snprintf (char *, size_t, __const__ char *, ...);
    209 char *tempnam (__const__ char *, __const__ char *);
    210 int vfscanf (FILE *, __const__ char *, va_list);
    211 int vscanf (__const__ char *, va_list);
    212 int vsnprintf (char *, size_t, __const__ char *, va_list);
    213 int vsscanf (__const__ char *, __const__ char *, va_list);
    214534
    215535#endif
     
    234554FILE *_popen (__const__ char *, __const__ char *);
    235555int _putw (int, FILE *);
    236 int _setbuffer (FILE *, char *, size_t);
     556void _setbuffer (FILE *, char *, int);
    237557int _snprintf (char *, size_t, __const__ char *, ...);
    238558char *_tempnam (__const__ char *, __const__ char *);
     
    240560
    241561#endif
    242 
    243 
    244 #if defined (__cplusplus)
    245 }
    246 #endif
    247 
    248 #endif /* not _STDIO_H */
     562/* bird: end of EMX isms. */
     563
     564__END_DECLS
     565#endif /* !_STDIO_H_ */
     566
  • trunk/src/emx/include/sys/_types.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r731 r732  
    5757typedef int             __nl_item;
    5858typedef __uint16_t      __nlink_t;      /* link count */
    59 #if 1 /* bird: emx */
     59#if 0 /* bird: emx */
    6060typedef __int32_t       __off_t;        /* file offset */
    6161#else
  • trunk/src/emx/include/sys/dir.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r731 r732  
    1 /* sys/dir.h (emx+gcc) */
     1/*
     2 * Copyright (c) 1982, 1986, 1989, 1993
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 * 3. All advertising materials mentioning features or use of this software
     14 *    must display the following acknowledgement:
     15 *      This product includes software developed by the University of
     16 *      California, Berkeley and its contributors.
     17 * 4. Neither the name of the University nor the names of its contributors
     18 *    may be used to endorse or promote products derived from this software
     19 *    without specific prior written permission.
     20 *
     21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31 * SUCH DAMAGE.
     32 *
     33 *      @(#)dir.h       8.2 (Berkeley) 1/4/94
     34 * $FreeBSD: src/sys/sys/dir.h,v 1.6 1999/08/28 00:51:39 peter Exp $
     35 */
    236
    3 #ifndef _SYS_DIR_H
    4 #define _SYS_DIR_H
     37/** @file
     38 * FreeBSD 5.1
     39 */
    540
    6 #if !defined (_SYS_TYPES_H)
    7 #warning <sys/dir.h> requires <sys/types.h>
    8 #include <sys/types.h>
     41#ifndef _SYS_DIR_H_
     42#define _SYS_DIR_H_
     43
     44#if __GNUC__
     45#warning "The information in this file should be obtained from <dirent.h>"
     46#warning "and is provided solely (and temporarily) for backward compatibility."
    947#endif
    1048
    11 #if defined (__cplusplus)
    12 extern "C" {
    13 #endif
     49#include <dirent.h>
    1450
    15 #if !defined (MAXNAMLEN)
    16 #define MAXNAMLEN  260
    17 #endif
     51/*
     52 * Backwards compatibility.
     53 */
     54#define direct          dirent
     55#define DIRSIZ(dp)      _GENERIC_DIRSIZ(dp)
    1856
    19 #if !defined (MAXPATHLEN)
    20 #define MAXPATHLEN 260
    21 #endif
    22 
    23 #if !defined (A_RONLY)
    24 #define A_RONLY   0x01
    25 #define A_HIDDEN  0x02
    26 #define A_SYSTEM  0x04
    27 #define A_LABEL   0x08
    28 #define A_DIR     0x10
    29 #define A_ARCHIVE 0x20
    30 #endif
    31 
    32 #define _DIRECT_D_MODE_RENAMED_D_ATTR
    33 
    34 struct direct
    35 {
    36   ino_t          d_ino;                 /* Almost not used           */
    37   int            d_reclen;              /* Almost not used           */
    38   int            d_namlen;              /* Length of d_name          */
    39   char           d_name[MAXNAMLEN + 1]; /* File name, 0 terminated   */
    40   long           d_size;                /* File size (bytes)         */
    41   unsigned short d_attr;                /* OS file attributes        */
    42   unsigned short d_time;                /* OS file modification time */
    43   unsigned short d_date;                /* OS file modification date */
    44 };
    45 
    46 struct _dircontents
    47 {
    48   char *                _d_entry;
    49   long                  _d_size;
    50   unsigned short        _d_attr;
    51   unsigned short        _d_time;
    52   unsigned short        _d_date;
    53   struct _dircontents * _d_next;
    54 };
    55 
    56 struct _dirdesc
    57 {
    58   int                   dd_id;
    59   long                  dd_loc;
    60   struct _dircontents * dd_contents;
    61   struct _dircontents * dd_cp;
    62 };
    63 
    64 typedef struct _dirdesc DIR;
    65 
    66 DIR *opendir (__const__ char *name);
    67 struct direct *readdir (DIR *dirp);
    68 void seekdir (DIR *dirp, long off);
    69 long telldir (DIR *dirp);
    70 int closedir (DIR *dirp);
    71 void rewinddir (DIR *dirp);
    72 
    73 #if defined (__cplusplus)
    74 }
    75 #endif
    76 
    77 #endif /* not SYS_DIR_H */
     57#endif /* !_SYS_DIR_H_ */
  • trunk/src/emx/include/sys/dirent.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r731 r732  
    1 /* sys/dirent.h (emx+gcc) */
     1/*-
     2 * Copyright (c) 1989, 1993
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 * 3. All advertising materials mentioning features or use of this software
     14 *    must display the following acknowledgement:
     15 *      This product includes software developed by the University of
     16 *      California, Berkeley and its contributors.
     17 * 4. Neither the name of the University nor the names of its contributors
     18 *    may be used to endorse or promote products derived from this software
     19 *    without specific prior written permission.
     20 *
     21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31 * SUCH DAMAGE.
     32 *
     33 *      @(#)dirent.h    8.3 (Berkeley) 8/10/94
     34 * $FreeBSD: src/sys/sys/dirent.h,v 1.13 2002/09/10 18:12:16 mike Exp $
     35 */
    236
    3 #ifndef _SYS_DIRENT_H
    4 #define _SYS_DIRENT_H
     37/** @file
     38 * FreeBSD 5.1
     39 * @changed bird: Merged in all the EMX stuff.
     40 */
    541
    6 #if !defined (_SYS_TYPES_H)
    7 #warning <sys/dirent.h> requires <sys/types.h>
    8 #include <sys/types.h>
     42#ifndef _SYS_DIRENT_H_
     43#define _SYS_DIRENT_H_
     44
     45#include <sys/cdefs.h>
     46#include <sys/_types.h>
     47
     48/*
     49 * The dirent structure defines the format of directory entries returned by
     50 * the getdirentries(2) system call.
     51 *
     52 * A directory entry has a struct dirent at the front of it, containing its
     53 * inode number, the length of the entry, and the length of the name
     54 * contained in the entry.  These are followed by the name padded to a 4
     55 * byte boundary with null bytes.  All names are guaranteed null terminated.
     56 * The maximum length of a name in a directory is MAXNAMLEN.
     57 */
     58
     59struct dirent {
     60        __uint32_t d_fileno;            /* file number of entry */
     61        __uint16_t d_reclen;            /* length of this record */
     62        __uint8_t  d_type;              /* file type, see below */
     63        __uint8_t  d_namlen;            /* length of string in d_name */
     64#if __BSD_VISIBLE
     65#ifndef MAXNAMLEN  /* bird: emx */
     66#define MAXNAMLEN       260 /* bird: changed from 255. */
     67#endif             /* bird: emx */
     68        char    d_name[MAXNAMLEN + 1];  /* name must be no longer than this */
     69#else
     70        char    d_name[260 + 1];        /* bird: changed from 255. */ /* name must be no longer than this */
     71#endif
     72/* bird: Extra EMX fields - start */
     73        __uint8_t  d_attr;              /* OS file attributes        */
     74        __uint16_t d_time;              /* OS file modification time */
     75        __uint16_t d_date;              /* OS file modification date */
     76        __off_t    d_size;              /* File size (bytes)         */
     77/* bird: Extra EMX fields - end */
     78};
     79
     80#if __BSD_VISIBLE
     81/*
     82 * File types
     83 */
     84#define DT_UNKNOWN       0
     85#define DT_FIFO          1
     86#define DT_CHR           2
     87#define DT_DIR           4
     88#define DT_BLK           6
     89#define DT_REG           8
     90#define DT_LNK          10
     91#define DT_SOCK         12
     92#define DT_WHT          14
     93
     94/*
     95 * Convert between stat structure types and directory types.
     96 */
     97#define IFTODT(mode)    (((mode) & 0170000) >> 12)
     98#define DTTOIF(dirtype) ((dirtype) << 12)
     99
     100/*
     101 * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
     102 * the directory entry.  This requires the amount of space in struct direct
     103 * without the d_name field, plus enough space for the name with a terminating
     104 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
     105 *
     106 * XXX although this macro is in the implementation namespace, it requires
     107 * a manifest constant that is not.
     108 */
     109#define _GENERIC_DIRSIZ(dp) \
     110    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
     111#endif /* __BSD_VISIBLE */
     112
     113#ifdef _KERNEL
     114#define GENERIC_DIRSIZ(dp)      _GENERIC_DIRSIZ(dp)
    9115#endif
    10116
    11 #if !defined (MAXNAMLEN)
    12 #define MAXNAMLEN  260
    13 #endif
     117
     118/* bird: EMX stuff */
     119#define _DIRENT_D_MODE_RENAMED_D_ATTR
    14120
    15121#if !defined (MAXPATHLEN)
     
    26132#endif
    27133
    28 #define _DIRENT_D_MODE_RENAMED_D_ATTR
    29 
    30 struct dirent
    31 {
    32   ino_t          d_ino;                 /* Almost not used           */
    33   int            d_reclen;              /* Almost not used           */
    34   int            d_namlen;              /* Length of d_name          */
    35   char           d_name[MAXNAMLEN + 1]; /* File name, 0 terminated   */
    36   long           d_size;                /* File size (bytes)         */
    37   unsigned short d_attr;                /* OS file attributes        */
    38   unsigned short d_time;                /* OS file modification time */
    39   unsigned short d_date;                /* OS file modification date */
    40 };
    41 
    42134#endif /* not SYS_DIRENT_H */
  • trunk/src/emx/include/sys/dirtree.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r731 r732  
    44#define _SYS_DIRTREE_H
    55
    6 #if defined (__cplusplus)
    7 extern "C" {
     6#include <sys/cdefs.h>
     7#include <sys/_types.h>
     8
     9#if !defined(_TIME_T_DECLARED) && !defined(_TIME_T)
     10typedef __time_t        time_t;
     11#define _TIME_T_DECLARED
     12#define _TIME_T
    813#endif
    914
    10 #if !defined (_TIME_T)
    11 #define _TIME_T
    12 typedef unsigned long time_t;
     15#if !defined(_OFF_T_DECLARED) && !defined(_OFF_T)
     16typedef __off_t         off_t;          /* file offset */
     17#define _OFF_T_DECLARED
     18#define _OFF_T
    1319#endif
    1420
     
    1824  struct _dt_node *sub;    /* Pointer to next level (child) */
    1925  char *name;              /* Name */
    20   long size;               /* File size */
     26  off_t size;              /* File size */
    2127  long user;               /* Available for user */
    2228  time_t mtime;            /* Timestamp for last update */
    2329  unsigned char attr;      /* Attributes */
    2430};
    25 
    2631
    2732struct _dt_tree
     
    3439#define _DT_NOCPDIR  0x8000
    3540
    36 void _dt_free (struct _dt_tree *dt);
     41__BEGIN_DECLS
     42void    _dt_free (struct _dt_tree *dt);
    3743struct _dt_tree *_dt_read (__const__ char *dir, __const__ char *mask,
    3844    unsigned flags);
    39 void _dt_sort (struct _dt_tree *dt, __const__ char *spec);
    40 int _dt_split (__const__ char *src, char *dir, char *mask);
     45void    _dt_sort (struct _dt_tree *dt, __const__ char *spec);
     46int     _dt_split (__const__ char *src, char *dir, char *mask);
     47__END_DECLS
    4148
    42 #if defined (__cplusplus)
    43 }
    44 #endif
    45 
    46 #endif /* not _SYS_DIRTREE_H */
     49#endif /* !_SYS_DIRTREE_H */
  • trunk/src/emx/src/lib/io/_flushst.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    5252              w = 0;
    5353              if (pflags != NULL && (*pflags & O_APPEND))
    54                 lseek (fh, 0L, SEEK_END);
     54                lseek (fh, 0, SEEK_END);
    5555            }
    5656          stream->_ptr = stream->_buffer;
  • trunk/src/emx/src/lib/io/_seekhdr.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    2222      unsigned short hdr_loc_hi;
    2323    } patch;
    24   long original_pos;
     24  off_t original_pos;
    2525  int saved_errno;
    2626
     
    3737    goto failure;
    3838  if (lseek (handle, original_pos + patch.hdr_loc_lo
    39               + 65536L * patch.hdr_loc_hi, SEEK_SET) == -1)
     39              + 65536 * patch.hdr_loc_hi, SEEK_SET) == -1)
    4040    goto failure;
    4141  return 0;
  • trunk/src/emx/src/lib/io/_vsopen.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1414/*       O_TEXT|O_WRONLY  does/can not overwrite Ctrl-Z */
    1515
    16 #define FALSE   0
    17 #define TRUE    1
    18 
    1916int _fmode_bin;                 /* Set non-zero to make binary mode default */
    2017
    2118#define SH_MASK           0x70
    2219
    23 /* This function may be called as follows (assuming that oflag does
    24    not include O_CREAT nor O_SIZE):
     20/**
     21 * This function may be called as follows (assuming that fOpen does
     22 *  not include O_CREAT nor O_SIZE):
     23 *
     24 *  _vsopen(pszName, fOpen, fShare)
     25 *  _vsopen(pszName, fOpen | O_CREAT, fShare, pmode)
     26 *  _vsopen(pszName, fOpen | O_SIZE, fShare, off_t size)
     27 *  _vsopen(pszName, fOpen | O_CREAT | O_SIZE, fShare, pmode, off_t size)
     28 *
     29 * @remark O_SIZE means a off_t sized argument not unsigned long as emxlib say.
     30 */
     31int _vsopen(const char *pszName, int fOpen, int fShare, va_list va)
     32{
     33    int     hFile;
     34    /** Flags is for __open.
     35     *  0 -  1  Access mode (O_RDONLY, O_WRONLY, O_RDWR).
     36     *  4 -  6  Shared (SH_*)
     37     *  8 - 15  File attributes (DOS style).
     38     * 16 - 23  __open flags, _SO_*
     39     */
     40    int     fFlags;
     41    int    *pfFlags;
     42    int     saved_errno;
     43    int     bits;
     44    char    chDummy;
     45    int     fCtrlZKludge = 0;
     46    off_t   cbInitial;
    2547
    26    _vsopen (name, oflag, shflag)
    27    _vsopen (name, oflag | O_CREAT, shflag, pmode)
    28    _vsopen (name, oflag | O_SIZE, shflag, size)
    29    _vsopen (name, oflag | O_CREAT | O_SIZE, shflag, pmode, size) */
    30 
    31 int _vsopen (const char *name, int oflag, int shflag, va_list va)
    32 {
    33   int handle, flags, *pflags, saved_errno;
    34   int bits;
    35   char dummy, ctrlz_kludge = FALSE;
    36   unsigned long initial_size;
    37 
    38   if ((oflag & O_ACCMODE) == O_RDONLY && (oflag & (O_TRUNC|O_CREAT)))
     48    /*
     49     * Validate input
     50     */
     51    if ((fOpen & O_ACCMODE) == O_RDONLY && (fOpen & (O_TRUNC|O_CREAT)))
    3952    {
    40       errno = EINVAL;
    41       return -1;
    42     }
    43 
    44   bits = oflag & (O_ACCMODE|O_NDELAY|O_APPEND);
    45   if (oflag & O_BINARY)
    46     /* do nothing */;
    47   else if (oflag & O_TEXT)
    48     bits |= O_TEXT;
    49   else if (_fmode_bin == 0)          /* neither O_TEXT nor O_BINARY given */
    50     bits |= O_TEXT;
    51 
    52   if ((bits & O_TEXT) && (oflag & O_APPEND) && (oflag & O_ACCMODE) == O_WRONLY)
    53     {
    54       /* The caller requests to open a text file for appending in
    55          write-only.  To remove the Ctrl-Z (if there is any), we have
    56          to temporarily open the file in read/write mode. */
    57 
    58       flags = O_RDWR | (shflag & SH_MASK);
    59       ctrlz_kludge = TRUE;
    60     }
    61   else
    62     flags = (oflag & O_ACCMODE) | (shflag & SH_MASK);
    63 
    64   if (oflag & O_CREAT)
    65     {
    66       int attr, pmode;
    67 
    68       attr = 0;
    69       pmode = va_arg (va, int);
    70       if (!(pmode & S_IWRITE))
    71         attr |= _A_RDONLY;
    72       flags |= (attr << 8) | _SO_CREAT;
    73       if (oflag & O_EXCL)
    74         flags |= _SO_EXCL;
    75     }
    76 
    77   if (oflag & O_TRUNC)
    78     flags |= _SO_TRUNC;
    79 
    80   if (oflag & O_NOINHERIT)
    81     flags |= _SO_NOINHERIT;
    82 
    83   if (oflag & O_SYNC)
    84     flags |= _SO_SYNC;
    85 
    86   initial_size = 0;
    87   if (oflag & O_SIZE)
    88     {
    89       initial_size = va_arg (va, unsigned long);
    90       flags |= _SO_SIZE;
    91     }
    92    
    93   saved_errno = errno;
    94   handle = __open (name, flags, initial_size);
    95   if (handle < 0 && ctrlz_kludge && errno == EACCES)
    96     {
    97       /* Perhaps read access is denied.  Try again. */
    98       errno = saved_errno;
    99       ctrlz_kludge = FALSE;
    100       flags = (flags & ~O_ACCMODE) | (oflag & O_ACCMODE);
    101       handle = __open (name, flags, initial_size);
    102     }
    103   if (handle < 0)
    104     return -1;
    105 
    106   if (__ioctl1 (handle, 0) & 0x80)
    107     {
    108       bits |= F_DEV;
    109       oflag &= ~O_APPEND;
    110     }
    111 
    112   if (!(bits & F_DEV) && (bits & O_TEXT))
    113     {
    114       long size;
    115 
    116       /* Remove the last character of the file if it is a Ctrl-Z.  Do
    117          this even if O_SIZE is given as we don't know whether the
    118          file existed before; removing a spurious Ctrl-Z due to O_SIZE
    119          should be harmless. */
    120 
    121       /* DEC Pathworks seems to treat the offset as unsigned number.
    122          Therefore we do not use __lseek (handle, -1L, SEEK_END). */
    123 
    124       size = __lseek (handle, 0L, SEEK_END);
    125       if (size > 0 && __lseek (handle, size - 1, SEEK_SET) != -1L
    126           && __read (handle, &dummy, 1) == 1 && dummy == 0x1a)
    127         __ftruncate (handle, size - 1); /* Remove Ctrl-Z */
    128       __lseek (handle, 0L, SEEK_SET);
    129     }
    130 
    131   if (ctrlz_kludge)
    132     {
    133       /* Reopen the handle in write-only mode. */
    134 
    135       __close (handle);
    136       flags = (flags & ~O_ACCMODE) | (oflag & O_ACCMODE);
    137       flags &= ~_SO_EXCL;       /* Ignore O_EXCL */
    138       handle = __open (name, flags, initial_size);
    139       if (handle < 0)
     53        errno = EINVAL;
    14054        return -1;
    14155    }
    14256
    143   pflags = _fd_init (handle);
    144   if (pflags == NULL)
     57    /*
     58     * Build fFlags.
     59     */
     60    bits = fOpen & (O_ACCMODE|O_NDELAY|O_APPEND);
     61    if (fOpen & O_BINARY)
     62        /* do nothing */;
     63    else if (fOpen & O_TEXT)
     64        bits |= O_TEXT;
     65    else if (_fmode_bin == 0)          /* neither O_TEXT nor O_BINARY given */
     66        bits |= O_TEXT;
     67
     68    if ((bits & O_TEXT) && (fOpen & O_APPEND) && (fOpen & O_ACCMODE) == O_WRONLY)
    14569    {
    146       __close (handle);
    147       errno = EMFILE;
    148       return -1;
     70        /* The caller requests to open a text file for appending in
     71           write-only.  To remove the Ctrl-Z (if there is any), we have
     72           to temporarily open the file in read/write mode. */
     73
     74        fFlags = O_RDWR | (fShare & SH_MASK);
     75        fCtrlZKludge = 1;
     76    }
     77    else
     78        fFlags = (fOpen & O_ACCMODE) | (fShare & SH_MASK);
     79
     80    /* pmode(=attr) - attr is 2nd byte of flags. */
     81    if (fOpen & O_CREAT)
     82    {
     83        int attr, pmode;
     84
     85        attr = 0;
     86        pmode = va_arg(va, int);
     87        if (!(pmode & S_IWRITE))
     88            attr |= _A_RDONLY;
     89        fFlags |= (attr << 8) | _SO_CREAT;
     90        if (fOpen & O_EXCL)
     91            fFlags |= _SO_EXCL;
    14992    }
    15093
    151   *pflags = bits;
     94    if (fOpen & O_TRUNC)
     95        fFlags |= _SO_TRUNC;
    15296
    153   /* When opening a file for appending, move to the end of the file.
    154      This is required for passing the handle to a child process. */
     97    if (fOpen & O_NOINHERIT)
     98        fFlags |= _SO_NOINHERIT;
    15599
    156   if (!(bits & F_DEV) && (bits & O_APPEND))
    157     __lseek (handle, 0L, SEEK_END);
    158   errno = saved_errno;
     100    if (fOpen & O_SYNC)
     101        fFlags |= _SO_SYNC;
    159102
    160   return handle;
     103    /* Initial file size */
     104    cbInitial = 0;
     105    if (fOpen & O_SIZE)
     106    {
     107        cbInitial = va_arg(va, off_t);
     108        fFlags |= _SO_SIZE;
     109    }
     110
     111    /*
     112     * Open - note Ctrl-Z hack.
     113     */
     114    saved_errno = errno;
     115    hFile = __open(pszName, fFlags, cbInitial);
     116    if (hFile < 0 && fCtrlZKludge && errno == EACCES)
     117    {
     118        /* Perhaps read access is denied. Try again. */
     119        errno = saved_errno;
     120        fCtrlZKludge = 0;
     121        fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
     122        hFile = __open(pszName, fFlags, cbInitial);
     123    }
     124    if (hFile < 0)
     125        return -1;
     126
     127    /*
     128     * Check what we got a handle to.
     129     */
     130    if (__ioctl1(hFile, 0) & 0x80)
     131    {
     132        bits |= F_DEV;
     133        fOpen &= ~O_APPEND;
     134    }
     135
     136    /*
     137     * For text files we shall remove eventual ending Ctrl-Z.
     138     */
     139    if (!(bits & F_DEV) && (bits & O_TEXT))
     140    {
     141        off_t cbSize;
     142
     143        /* Remove the last character of the file if it is a Ctrl-Z.  Do
     144           this even if O_SIZE is given as we don't know whether the
     145           file existed before; removing a spurious Ctrl-Z due to O_SIZE
     146           should be harmless. */
     147
     148        cbSize = __lseek(hFile, -1, SEEK_END);
     149        if (cbSize >= 0)
     150        {
     151            if (__read(hFile, &chDummy, 1) == 1 && chDummy == 0x1a)
     152                __ftruncate(hFile, cbSize); /* Remove Ctrl-Z */
     153            __lseek(hFile, 0L, SEEK_SET);
     154        }
     155    }
     156
     157    /*
     158     * Reopen the file in write-only mode if Ctrl-Z hack applied.
     159     */
     160    if (fCtrlZKludge)
     161    {
     162        __close(hFile);
     163        fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
     164        fFlags &= ~_SO_EXCL;       /* Ignore O_EXCL */
     165        hFile = __open(pszName, fFlags, cbInitial);
     166        if (hFile < 0)
     167            return -1;
     168    }
     169
     170    /*
     171     * Set file bits.
     172     */
     173    pfFlags = _fd_init(hFile);
     174    if (!pfFlags)
     175    {
     176        __close(hFile);
     177        errno = EMFILE;
     178        return -1;
     179    }
     180    *pfFlags = bits;
     181
     182    /*
     183     * When opening a file for appending, move to the end of the file.
     184     * This is required for passing the file to a child process.
     185     */
     186    if (!(bits & F_DEV) && (bits & O_APPEND))
     187        __lseek(hFile, 0L, SEEK_END);
     188    errno = saved_errno;
     189
     190    return hFile;
    161191}
  • trunk/src/emx/src/lib/io/chsize.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    88#include <emx/syscalls.h>
    99
    10 int _STD(chsize) (int handle, long length)
     10int _STD(chsize) (int handle, off_t length)
    1111{
    12   long n;
    13   int i, j, *pflags;
     12  off_t n;
     13  off_t i;
     14  int j, *pflags;
    1415  char zeros[4096];
    1516
     
    1920      return -1;
    2021    }
    21   n = (long)__lseek (handle, 0L, SEEK_END);
    22   if (n == -1L)
     22  n = __lseek (handle, 0, SEEK_END);
     23  if (n == -1)
    2324    return -1;
    2425  if (__chsize (handle, length) != 0)
  • trunk/src/emx/src/lib/io/eof.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r731 r732  
    99{
    1010  int *pflags;
    11   long cur, len;
     11  off_t cur, len;
    1212
    1313  if ((pflags = _fd_flags (handle)) == NULL)
  • trunk/src/emx/src/lib/io/fflush.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1515{
    1616  int result, n, ft, saved_errno;
    17   long pos;
     17  off_t pos;
    1818
    1919  result = 0;
     
    5252         write error occurs, otherwise zero." */
    5353      pos = _ftell_nolock (stream);
    54       if (pos != -1L)
     54      if (pos != -1)
    5555        lseek (stream->_handle, pos, SEEK_SET);
    5656    }
  • trunk/src/emx/src/lib/io/fgetpos.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    66int _STD(fgetpos) (FILE *stream, fpos_t *pos)
    77{
    8   long n;
    9 
    10   if ((n = ftell (stream)) == (long)EOF)
     8  __off_t off;
     9  *pos = EOF;                           /* crash test */
     10  off = ftello (stream);
     11  if (off == EOF)
    1112    return EOF;
    12   pos->_pos = n;
    13   pos->_reserved1 = 0;
    14   pos->_mbstate = stream->_mbstate;
    15   pos->_reserved2 = 0;
     13  *pos = (fpos_t)off;
    1614  return 0;
    1715}
  • trunk/src/emx/src/lib/io/fileleng.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    55#include <emx/syscalls.h>
    66
    7 long _STD(filelength) (int handle)
     7off_t _STD(filelength) (int handle)
    88{
    9   long cur, n;
     9  off_t offcur, offend;
    1010
    11   cur = (long)__lseek (handle, 0L, SEEK_CUR);
    12   if (cur == -1L)
     11  offcur = __lseek (handle, 0L, SEEK_CUR);
     12  if (offcur == -1)
    1313    return -1;
    14   n = (long)__lseek (handle, 0L, SEEK_END);
    15   __lseek (handle, cur, SEEK_SET);
    16   return n;
     14  offend = __lseek (handle, 0L, SEEK_END);
     15  __lseek (handle, offcur, SEEK_SET);
     16  return offend;
    1717}
  • trunk/src/emx/src/lib/io/fseek.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1111#include <emx/io.h>
    1212
    13 int _fseek_nolock (FILE *stream, long offset, int origin)
     13int _fseek_nolock (FILE *stream, off_t offset, int origin)
    1414{
    15   long cur_pos;
     15  off_t cur_pos;
    1616  int fflush_result, *pflags;
    1717
     
    3535      && bbuf (stream) && stream->_ungetc_count == 0)
    3636    {
    37       long file_pos, end_pos, buf_pos;
     37      off_t file_pos, end_pos, buf_pos;
    3838      int text_mode, n;
    3939
     
    4848      else if (origin == SEEK_END)
    4949        {
    50           end_pos = lseek (stream->_handle, 0L, SEEK_END);
     50          end_pos = lseek (stream->_handle, 0, SEEK_END);
    5151          lseek (stream->_handle, file_pos, SEEK_SET);
    5252          if (end_pos == -1)
     
    9696              if (offset >= buf_pos)
    9797                {
    98                   long tmp_pos;
     98                  off_t tmp_pos;
    9999
    100100                  /* The new position is within the buffer.  Adjust
     
    179179
    180180
     181int _STD(fseeko) (FILE *stream, off_t offset, int origin)
     182{
     183    int result;
     184
     185    STREAM_LOCK (stream);
     186    result = _fseek_nolock (stream, offset, origin);
     187    STREAM_UNLOCK (stream);
     188    return result;
     189}
     190
    181191int _STD(fseek) (FILE *stream, long offset, int origin)
    182192{
    183   int result;
    184 
    185   STREAM_LOCK (stream);
    186   result = _fseek_nolock (stream, offset, origin);
    187   STREAM_UNLOCK (stream);
    188   return result;
     193  return fseeko (stream, (off_t)offset, origin);
    189194}
  • trunk/src/emx/src/lib/io/fsetpos.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    66int _STD(fsetpos) (FILE *stream, const fpos_t *pos)
    77{
    8   if (fseek (stream, pos->_pos, SEEK_SET) != 0)
     8  if (fseeko (stream, (__off_t)*pos, SEEK_SET) != 0)
    99    return -1;
    10   stream->_mbstate = pos->_mbstate;
    1110  return 0;
    1211}
  • trunk/src/emx/src/lib/io/ftell.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1111#include <emx/io.h>
    1212
    13 long _ftell_nolock (FILE *stream)
     13off_t _ftell_nolock (FILE *stream)
    1414{
    15   long pos;
    16   int *pflags;
     15  off_t pos;
     16  int * pflags;
    1717
    1818  if (stream->_flags & _IOSPECIAL)
     
    9898}
    9999
     100__off_t _STD(ftello) (FILE *stream)
     101{
     102  off_t off;
     103
     104  STREAM_LOCK (stream);
     105  off = _ftell_nolock (stream);
     106  STREAM_UNLOCK (stream);
     107  return off;
     108}
    100109
    101110long _STD(ftell) (FILE *stream)
    102111{
    103   long r;
    104 
    105   STREAM_LOCK (stream);
    106   r = _ftell_nolock (stream);
    107   STREAM_UNLOCK (stream);
    108   return r;
     112  off_t off = ftello (stream);
     113#if OFF_MAX > LONG_MAX
     114  if (off > LONG_MAX)
     115    {
     116      errno = EOVERFLOW;
     117      return -1;
     118    }
     119  return (long)off;
     120#else
     121  return off;
     122#endif
    109123}
  • trunk/src/emx/src/lib/io/lseek.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r731 r732  
    1010{
    1111  int *pflags, *pla;
    12   long n, cur;
     12  off_t n, cur;
    1313
    1414  if ((pflags = _fd_flags (handle)) == NULL
     
    2828          return -1;
    2929        }
    30       cur = (long)__lseek (handle, 0L, SEEK_CUR);
     30      cur = __lseek (handle, 0, SEEK_CUR);
    3131      if (cur == -1L)
    3232        return -1;
    33       n = (long)__lseek (handle, 0L, origin);
     33      n = __lseek (handle, 0, origin);
    3434      if (n + offset < 0)
    3535        {
     
    4040      offset += n; origin = SEEK_SET;
    4141    }
    42   n = (long)__lseek (handle, offset, origin);
    43   if (n == -1L)
     42  n = __lseek (handle, offset, origin);
     43  if (n == -1)
    4444    return -1;
    4545  else
  • trunk/src/emx/src/lib/io/open.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    77#include <emx/io.h>
    88
     9/**
     10 * @remark O_SIZE means a off_t sized argument not unsigned long as emxlib say.
     11 */
    912int _STD(open) (const char *name, int oflag, ...)
    1013{
  • trunk/src/emx/src/lib/io/rewind.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1313  STREAM_LOCK (stream);
    1414  _fflush_nolock (stream);
    15   _fseek_nolock (stream, 0L, SEEK_SET);
     15  _fseek_nolock (stream, 0, SEEK_SET);
    1616  stream->_flags &= ~_IOERR;
    1717  STREAM_UNLOCK (stream);
  • trunk/src/emx/src/lib/io/setbuf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    44#include <stdio.h>
    55
    6 int _STD(setbuf) (FILE *stream, char *buffer)
     6void _STD(setbuf) (FILE *stream, char *buffer)
    77{
    8   return setvbuf (stream, buffer, (buffer != NULL ? _IOFBF : _IONBF), BUFSIZ);
     8  setvbuf (stream, buffer, (buffer != NULL ? _IOFBF : _IONBF), BUFSIZ);
    99}
  • trunk/src/emx/src/lib/io/setbuffe.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    44#include <stdio.h>
    55
    6 int _STD(setbuffer) (FILE *stream, char *buffer, size_t size)
     6void _STD(setbuffer) (FILE *stream, char *buffer, int size)
    77{
    8   return setvbuf (stream, buffer, (buffer != NULL ? _IOFBF : _IONBF), size);
     8  setvbuf (stream, buffer, (buffer != NULL ? _IOFBF : _IONBF), (size_t)size);
    99}
  • trunk/src/emx/src/lib/io/sopen.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r731 r732  
    66#include <emx/io.h>
    77
     8/**
     9 * @remark O_SIZE means a off_t sized argument not unsigned long as emxlib say.
     10 */
    811int _STD(sopen) (const char *name, int oflag, int shflag, ...)
    912{
  • trunk/src/emx/src/lib/io/tell.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    77#include <emx/syscalls.h>
    88
    9 long _STD(tell) (int handle)
     9off_t _STD(tell) (int handle)
    1010{
    1111  int *pflags, *pla;
    12   long n;
     12  off_t n;
    1313
    1414  if ((pflags = _fd_flags (handle)) == NULL
     
    1818      return -1;
    1919    }
    20   n = (long)__lseek (handle, 0L, SEEK_CUR);
     20  n = __lseek (handle, 0L, SEEK_CUR);
    2121  if (n == -1)
    2222    return n;
  • trunk/src/emx/src/lib/io/write.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    122122      else
    123123        {
    124           long pos;
     124          off_t pos;
    125125          int saved_errno;
    126126
    127127          saved_errno = errno;
    128           pos = __lseek (handle, -1L, SEEK_CUR);
     128          pos = __lseek (handle, -1, SEEK_CUR);
    129129          if (pos != -1)
    130130            __ftruncate (handle, pos);
     
    148148    }
    149149  if ((*pflags & (F_DEV|F_SOCKET|F_PIPE|O_APPEND)) == O_APPEND)
    150     __lseek (handle, 0L, SEEK_END);
     150    __lseek (handle, 0, SEEK_END);
    151151  if (nbyte == 0)                 /* Avoid truncation of file */
    152152    return 0;
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r731 r732  
    7373    "___locale_time" @53
    7474    "__sys_virtual_address_limit" @54
     75    "___pfnDosOpenL" @55
     76    "___pfnDosSetFileLocksL" @56
     77    "___pfnDosSetFilePtrL" @57
     78    "___pfnDosSetFileSizeL" @58
    7579
    7680; code
     
    808812    "__std_unsetenv" @831
    809813    "__std_lockf" @832
     814    "___init_largefileio" @833
     815    "__std_fseeko" @834
     816    "__std_ftello" @835
     817    "__std_readdir_r" @836
  • trunk/src/emx/src/lib/misc/dirent.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r731 r732  
    1212#include <emx/syscalls.h>
    1313
    14 struct _dircontents
    15 {
    16   char *                _d_entry;
    17   long                  _d_size;
    18   unsigned short        _d_attr;
    19   unsigned short        _d_time;
    20   unsigned short        _d_date;
    21   struct _dircontents * _d_next;
    22 };
    23 
    24 struct _dirdesc
    25 {
    26   int                   dd_id;
    27   long                  dd_loc;
    28   struct _dircontents * dd_contents;
    29   struct _dircontents * dd_cp;
    30   struct dirent         dd_dirent;
    31 };
    32 
    3314
    3415static int _readdir_ino = 31415926;
    3516
    36 static void free_dircontents (struct _dircontents *dp);
    37 static char *getdirent (const char *dir, struct _find *pfind,
    38     const char *base);
    39 
    40 int _STD(closedir) (DIR *dirp)
    41 {
    42   free_dircontents (dirp->dd_contents);
    43   free (dirp);
    44   return 0;
    45 }
    46 
    47 
    48 struct dirent *_STD(readdir) (DIR *dirp)
    49 {
    50   if (dirp->dd_cp == NULL)
     17/*******************************************************************************
     18*   Internal Functions                                                         *
     19*******************************************************************************/
     20static void free_dircontents(struct _dircontents *dp);
     21static char *getdirent(const char *dir, struct _find *pfind, const char *base);
     22
     23
     24static void free_dircontents(struct _dircontents *dp)
     25{
     26    while (dp != NULL)
     27    {
     28        void *pv = dp;
     29        dp = dp->_d_next;
     30        free(pv);
     31    }
     32}
     33
     34static char *getdirent(const char *dir, struct _find *pfind, const char *base)
     35{
     36    int rc;
     37
     38    if (dir != NULL)
     39        rc = __findfirst(dir, A_DIR | A_HIDDEN | A_SYSTEM, pfind);
     40    else
     41        rc = __findnext(pfind);
     42    if (rc)
     43        return NULL;
     44
     45    _fnlwr2(pfind->szName, base);
     46    return pfind->szName;
     47}
     48
     49DIR *_STD(opendir)(const char *name)
     50{
     51    struct stat             statb;
     52    struct _find            find;
     53    DIR *                   pdir;
     54    char *                  psz;
     55    char                    nbuf[MAXPATHLEN+1];
     56    int                     cchname;
     57    int                     saved_errno = errno;
     58
     59    /*
     60     * Put directory name in nbuf.
     61     */
     62    cchname = strlen(name);
     63    memcpy(nbuf, name, cchname + 1);
     64    psz = nbuf + cchname;
     65    if (_trslash (nbuf, cchname, 0))
     66    {
     67        nbuf[cchname++] = '.';        /* psz now points to '.' */
     68        nbuf[cchname] = 0;
     69    }
     70
     71    /*
     72     * Check that the directory exists and is a directory.
     73     */
     74    if (stat(nbuf, &statb) < 0)
     75        return NULL;
     76    if ((statb.st_mode & S_IFMT) != S_IFDIR)
     77    {
     78        errno = ENOTDIR;
     79        return NULL;
     80    }
     81
     82    /*
     83     * Start enumeration.
     84     * We're reading _everything_ now, which isn't such an good idea for
     85     * large directories actually. (I wouldn't try this on the FreeDB tree.)
     86     */
     87    pdir = malloc(sizeof(DIR));
     88    if (pdir == NULL)
     89    {
     90        errno = ENOMEM;
     91        return NULL;
     92    }
     93    if (!*psz) /* If dot was added. */
     94        *psz++ = '\\';
     95    strcpy(psz, "*.*");
     96    pdir->dd_loc = 0;
     97    pdir->dd_contents = NULL;
     98    pdir->dd_cp = NULL;
     99    psz = getdirent(nbuf, &find, name);
     100    if (psz == NULL)
     101    {
     102        errno = ENOMEM;
     103        return pdir; /* why no free and return? */
     104    }
     105
     106    do
     107    {
     108        struct _dircontents *   dp;
     109        int                     cch;
     110
     111        /*
     112         * Allocate memory for the directory entry.
     113         * To limit number of heap blocks and malloc+free calls, we allocate
     114         * on chunk of memory, placing the name after the struct.
     115         */
     116        cch = strlen(psz) + 1;
     117        dp = malloc(sizeof(struct _dircontents) + cch);
     118        if (dp == NULL)
     119        {
     120            free_dircontents(pdir->dd_contents);
     121            errno = ENOMEM;
     122            return NULL;
     123        }
     124        dp->_d_entry = (char*)(dp + 1);
     125
     126        /*
     127         * Enter the data.
     128         */
     129        memcpy(dp->_d_entry, psz, cch);
     130        if (pdir->dd_contents != NULL)
     131            pdir->dd_cp->_d_next = dp;
     132        else
     133            pdir->dd_contents = dp;
     134        pdir->dd_cp = dp;
     135        dp->_d_next = NULL;
     136        dp->_d_size = find.cbFile;
     137        dp->_d_attr = find.attr;
     138        dp->_d_time = find.time;
     139        dp->_d_date = find.date;
     140
     141        /*
     142         * Next entry.
     143         */
     144        psz = getdirent(NULL, &find, name);
     145    } while (psz != NULL);
     146
     147    /*
     148     * Position at start
     149     */
     150    pdir->dd_cp = pdir->dd_contents;
     151    errno = saved_errno; /* getdirent/findnext sets errno when done */
     152    return pdir;
     153}
     154
     155
     156int _STD(readdir_r)(DIR *dirp, struct dirent *pdent, struct dirent **ppdent)
     157{
     158    int cch;
     159    /* done? */
     160    if (dirp->dd_cp == NULL)
     161    {
     162        errno = ENOENT;
     163        *ppdent = NULL;
     164        return -1;
     165    }
     166
     167    /*
     168     * Copy the data over to the entry.
     169     */
     170    cch = strlen(dirp->dd_cp->_d_entry);
     171    memcpy(pdent->d_name, dirp->dd_cp->_d_entry, cch + 1);
     172    pdent->d_namlen = cch;
     173    pdent->d_reclen = pdent->d_namlen;
     174    pdent->d_ino = _readdir_ino++;
     175    if (_readdir_ino == 0)
     176        _readdir_ino = 1;
     177    pdent->d_type = (pdent->d_attr & A_DIR) ? DT_DIR : DT_REG;
     178    pdent->d_size = dirp->dd_cp->_d_size;
     179    pdent->d_attr = dirp->dd_cp->_d_attr;
     180    pdent->d_time = dirp->dd_cp->_d_time;
     181    pdent->d_date = dirp->dd_cp->_d_date;
     182
     183    /*
     184     * Advance the stream and return successfully.
     185     */
     186    dirp->dd_cp = dirp->dd_cp->_d_next;
     187    dirp->dd_loc++;
     188    *ppdent = pdent;
     189    return 0;
     190}
     191
     192
     193struct dirent *_STD(readdir)(DIR *dirp)
     194{
     195    struct dirent *p = &dirp->dd_dirent;
     196    if (!readdir_r(dirp, p, &p))
     197        return p;
    51198    return NULL;
    52   strcpy (dirp->dd_dirent.d_name, dirp->dd_cp->_d_entry);
    53   dirp->dd_dirent.d_namlen = strlen (dirp->dd_dirent.d_name);
    54   dirp->dd_dirent.d_reclen = dirp->dd_dirent.d_namlen;
    55   dirp->dd_dirent.d_ino = _readdir_ino++;
    56   if (_readdir_ino == 0)
    57     _readdir_ino = 1;
    58   dirp->dd_dirent.d_size = dirp->dd_cp->_d_size;
    59   dirp->dd_dirent.d_attr = dirp->dd_cp->_d_attr;
    60   dirp->dd_dirent.d_time = dirp->dd_cp->_d_time;
    61   dirp->dd_dirent.d_date = dirp->dd_cp->_d_date;
    62   dirp->dd_cp = dirp->dd_cp->_d_next;
    63   ++dirp->dd_loc;
    64   return &dirp->dd_dirent;
    65 }
    66 
    67 
    68 void _STD(seekdir) (DIR *dirp, long off)
    69 {
    70   long i;
    71   struct _dircontents *dp;
    72 
    73   if (off >= 0)
    74     {
    75       i = 0;
    76       for (dp = dirp->dd_contents; i < off && dp != NULL; dp = dp->_d_next)
    77         ++i;
    78       dirp->dd_loc = i;
    79       dirp->dd_cp = dp;
    80     }
    81   else
    82     errno = EINVAL;
    83 }
    84 
    85 
    86 void _STD(rewinddir) (DIR *dirp)
    87 {
    88   _seekdir (dirp, 0L);
    89 }
    90 
    91 
    92 long _STD(telldir) (DIR *dirp)
    93 {
    94   return dirp->dd_loc;
    95 }
    96 
    97 
    98 DIR *_STD(opendir) (const char *name)
    99 {
    100   struct stat statb;
    101   struct _find find;
    102   DIR *dirp;
    103   char *s;
    104   struct _dircontents *dp;
    105   char nbuf[MAXPATHLEN+1];
    106   int len;
    107 
    108   len = strlen (name);
    109   memcpy (nbuf, name, len + 1);
    110   s = nbuf + len;
    111   if (_trslash (nbuf, len, 0))
    112     {
    113       nbuf[len++] = '.';        /* s now points to '.' */
    114       nbuf[len] = 0;
    115     }
    116   if (stat (nbuf, &statb) < 0)
    117     return NULL;
    118   if ((statb.st_mode & S_IFMT) != S_IFDIR)
    119     {
    120       errno = ENOTDIR;
    121       return NULL;
    122     }
    123   dirp = malloc (sizeof (DIR));
    124   if (dirp == NULL)
    125     {
    126       errno = ENOMEM;
    127       return NULL;
    128     }
    129   if (*s == 0)
    130     *s++ = '\\';
    131   strcpy (s, "*.*");
    132   dirp->dd_loc = 0;
    133   dirp->dd_contents = NULL;
    134   dirp->dd_cp = NULL;
    135   s = getdirent (nbuf, &find, name);
    136   if (s == NULL)
    137     {
    138       errno = ENOMEM;
    139       return dirp;
    140     }
    141   do
    142     {
    143       dp = malloc (sizeof (struct _dircontents));
    144       if (dp == NULL)
    145         {
    146           free_dircontents (dirp->dd_contents);
    147           errno = ENOMEM;
    148           return NULL;
    149         }
    150       dp->_d_entry = malloc (strlen (s) + 1);
    151       if (dp->_d_entry == NULL)
    152         {
    153           free (dp);
    154           free_dircontents (dirp->dd_contents);
    155           errno = ENOMEM;
    156           return NULL;
    157         }
    158       if (dirp->dd_contents != NULL)
    159         dirp->dd_cp->_d_next = dp;
    160       else
    161         dirp->dd_contents = dp;
    162       dirp->dd_cp = dp;
    163       strcpy (dp->_d_entry, s);
    164       dp->_d_next = NULL;
    165       dp->_d_size = ((unsigned long)find.size_hi << 16) + find.size_lo;
    166       dp->_d_attr = find.attr;
    167       dp->_d_time = find.time;
    168       dp->_d_date = find.date;
    169       s = getdirent (NULL, &find, name);
    170     } while (s != NULL);
    171   dirp->dd_cp = dirp->dd_contents;
    172   return dirp;
    173 }
    174 
    175 
    176 static void free_dircontents (struct _dircontents *dp)
    177 {
    178   struct _dircontents *odp;
    179 
    180   while (dp != NULL)
    181     {
    182       if (dp->_d_entry != NULL)
    183         free(dp->_d_entry);
    184       odp = dp;
    185       dp = dp->_d_next;
    186       free (odp);
    187     }
    188 }
    189 
    190 
    191 static char *getdirent (const char *dir, struct _find *pfind, const char *base)
    192 {
    193   int rc;
    194 
    195   if (dir != NULL)
    196     rc = __findfirst (dir, A_DIR|A_HIDDEN|A_SYSTEM, pfind);
    197   else
    198     rc = __findnext (pfind);
    199   if (rc == 0)
    200     {
    201       _fnlwr2 (pfind->name, base);
    202       return pfind->name;
    203     }
    204   else
    205     return NULL;
    206 }
     199}
     200
     201
     202void _STD(seekdir)(DIR *dirp, long off)
     203{
     204    if (off >= 0)
     205    {
     206        long                i;
     207        struct _dircontents *dp;
     208
     209        i = 0;
     210        for (dp = dirp->dd_contents; i < off && dp != NULL; dp = dp->_d_next)
     211            ++i;
     212        dirp->dd_loc = i;
     213        dirp->dd_cp = dp;
     214    }
     215    else
     216        errno = EINVAL;
     217}
     218
     219
     220void _STD(rewinddir)(DIR *dirp)
     221{
     222    _seekdir(dirp, 0);
     223}
     224
     225
     226long _STD(telldir)(DIR *dirp)
     227{
     228    return dirp->dd_loc;
     229}
     230
     231
     232int _STD(closedir)(DIR *dirp)
     233{
     234    free_dircontents(dirp->dd_contents);
     235    free(dirp);
     236    return 0;
     237}
     238
  • trunk/src/emx/src/lib/misc/dtread.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r731 r732  
    5757static int _dt_match (struct _dt_rdata *dp)
    5858{
    59   if ((dp->flags & _DT_NOCPDIR) && (strcmp (dp->find.name, ".") == 0 ||
    60                                     strcmp (dp->find.name, "..") == 0))
     59  if ((dp->flags & _DT_NOCPDIR) && (strcmp (dp->find.szName, ".") == 0 ||
     60                                    strcmp (dp->find.szName, "..") == 0))
    6161    return 0;
    6262  return 1;
     
    6666static struct _dt_node *_dt_add (struct _dt_rdata *dp)
    6767{
    68   struct _dt_node *new;
     68  struct _dt_node *pnew;
    6969  struct tm tm;
    7070
    71   new = malloc (sizeof (*new));
    72   if (new == NULL)
     71  pnew = malloc (sizeof (*pnew));
     72  if (pnew == NULL)
    7373    {
    7474      errno = ENOMEM;
    7575      return NULL;
    7676    }
    77   new->next = NULL;
    78   new->sub = NULL;
    79   new->name = strdup (dp->find.name);
    80   if (new->name == NULL)
     77  pnew->next = NULL;
     78  pnew->sub = NULL;
     79  pnew->name = strdup (dp->find.szName);
     80  if (pnew->name == NULL)
    8181    {
    8282      errno = ENOMEM;
    8383      return NULL;
    8484    }
    85   _fnlwr2 (new->name, dp->dir);
    86   new->size = dp->find.size_lo + ((long)dp->find.size_hi << 16);
    87   new->user = 0;
    88   new->attr = dp->find.attr;
     85  _fnlwr2 (pnew->name, dp->dir);
     86  pnew->size = dp->find.cbFile;
     87  pnew->user = 0;
     88  pnew->attr = dp->find.attr;
    8989  tm.tm_sec = (dp->find.time & 0x1f) * 2;
    9090  tm.tm_min = (dp->find.time >> 5) & 0x3f;
     
    9494  tm.tm_year = ((dp->find.date >> 9) & 0x7f) + 1980 - 1900;
    9595  tm.tm_isdst = -1;             /* unknown */
    96   new->mtime = _mktime (&tm);
    97   _loc2gmt (&new->mtime, -1);
    98   return new;
     96  pnew->mtime = _mktime (&tm);
     97  _loc2gmt (&pnew->mtime, -1);
     98  return pnew;
    9999}
    100100
     
    103103                             int path_len)
    104104{
    105   struct _dt_node *new, **add;
     105  struct _dt_node *pnew, **add;
    106106  int r, len2;
    107107
     
    114114      if (!(dp->dir_pass && (dp->find.attr & A_DIR)) && _dt_match (dp))
    115115        {
    116           new = _dt_add (dp);
    117           if (new == NULL)
     116          pnew = _dt_add (dp);
     117          if (pnew == NULL)
    118118            return -1;
    119           *add = new;
    120           add = &new->next;
     119          *add = pnew;
     120          add = &pnew->next;
    121121        }
    122122      r = __findnext (&dp->find);
     
    132132          if ((dp->find.attr & A_DIR) && _dt_match (dp))
    133133            {
    134               new = _dt_add (dp);
    135               if (new == NULL)
     134              pnew = _dt_add (dp);
     135              if (pnew == NULL)
    136136                return -1;
    137               *add = new;
    138               add = &new->next;
     137              *add = pnew;
     138              add = &pnew->next;
    139139            }
    140140          r = __findnext (&dp->find);
     
    144144    }
    145145  if (dp->flags & _DT_TREE)
    146     for (new = *dst; new != NULL; new = new->next)
    147       if ((new->attr & A_DIR) && strcmp (new->name, ".") != 0
    148           && strcmp (new->name, "..") != 0)
     146    for (pnew = *dst; pnew != NULL; pnew = pnew->next)
     147      if ((pnew->attr & A_DIR) && strcmp (pnew->name, ".") != 0
     148          && strcmp (pnew->name, "..") != 0)
    149149        {
    150           len2 = strlen (new->name);
    151           strcpy (dp->path + path_len, new->name);
     150          len2 = strlen (pnew->name);
     151          strcpy (dp->path + path_len, pnew->name);
    152152          dp->path[path_len+len2] = '/';
    153           if (_dt_read_recurse (dp, &new->sub, path_len+len2+1) < 0)
     153          if (_dt_read_recurse (dp, &pnew->sub, path_len+len2+1) < 0)
    154154            return -1;
    155155        }
  • trunk/src/emx/src/lib/misc/fnexplod.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    3232  do
    3333    {
    34       if (strcmp (find.name, ".") != 0 &&
    35           strcmp (find.name, "..") != 0)
     34      if (   find.szName[0] != '.'
     35          || (   find.szName[1] != '\0'
     36              && (find.szName[1] != '.' || find.szName[2] != '\0')))
    3637        {
    3738          if (n + 1 >= a)
     
    4647              list = tmp;
    4748            }
    48           strcpy (p, find.name);
     49          strcpy (p, find.szName);
    4950          _fnlwr2 (name, name);
    5051          q = strdup (name);
     
    6162  return list;
    6263
    63 failure:           
     64failure:
    6465  if (list != NULL)
    6566    {
  • trunk/src/emx/src/lib/misc/wildcard.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    5252          do
    5353            {
    54               if (strcmp (find.name, ".") != 0 &&
    55                   strcmp (find.name, "..") != 0)
     54              if (   find.szName[0] != '.'
     55                  || (   find.szName[1] != '\0'
     56                      && (find.szName[1] != '.' || find.szName[2] != '\0')))
    5657                {
    57                   strcpy (p, find.name);
     58                  strcpy (p, find.szName);
    5859                  _fnlwr2 (p, line+1);
    5960                  q = strdup (line);
  • trunk/src/emx/src/lib/sys/__chsize.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/chsize.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/chsize.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   Copyright (c) 2003 Dimitry Froloff
     3   Copyright (c) 2003 knut st. osmundsen
     4 */
    25
    36#include "libc-alias.h"
    47#include <os2emx.h>
    58#include <emx/syscalls.h>
     9#include <limits.h>
     10#include <errno.h>
    611#include "syscalls.h"
    712
    8 int __chsize (int handle, long length)
     13
     14int __chsize (int hFile, __off_t cbFile)
    915{
    10   ULONG rc;
     16    ULONG rc;
    1117
    12   rc = DosSetFileSize (handle, length);
    13   if (rc != 0)
     18#if OFF_MAX > LONG_MAX
     19    if (__pfnDosSetFileSizeL)
     20        rc = __pfnDosSetFileSizeL(hFile, cbFile);
     21    else
    1422    {
    15       _sys_set_errno (rc);
    16       return -1;
     23        if (cbFile > LONG_MAX)
     24        {
     25            errno = EOVERFLOW;
     26            return -1;
     27        }
     28        rc = DosSetFileSize(hFile, cbFile);
    1729    }
    18   return 0;
     30#else
     31    rc = DosSetFileSize(hFile, cbFile);
     32#endif
     33
     34    if (rc)
     35    {
     36        _sys_set_errno(rc);
     37        return -1;
     38    }
     39    return 0;
    1940}
  • trunk/src/emx/src/lib/sys/__endthread.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1414    {
    1515      tp = _sys_thread_table[tid];
    16       if (tp->fd.find_handle != HDIR_CREATE)
    17         DosFindClose (tp->fd.find_handle);
     16      if (tp->fd.hdir != HDIR_CREATE)
     17        {
     18          DosFindClose (tp->fd.hdir);
     19          tp->fd.hdir = HDIR_CREATE;
     20        }
    1821      DosSubFreeMem (_sys_private_heap, tp, sizeof (thread_data));
    1922      _sys_thread_table[tid] = NULL;
  • trunk/src/emx/src/lib/sys/__fcntl.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r731 r732  
    6969   it's take from elsewhere. */
    7070
    71 static int __fcntl_locking (int handle, int request, struct flock *pflock)
     71static int __fcntl_locking (int hFile, int request, struct flock *pflock)
    7272{
    7373    APIRET        rc;
    74     FILESTATUS3   fsts3;
     74    union
     75    {
     76        FILESTATUS3     fsts3;
     77        FILESTATUS3L    fsts3L;
     78    } info;
     79#if OFF_MAX > LONG_MAX
     80    int     fLarge = 0;
     81#endif
    7582
    7683    /* check input */
     
    8289    }
    8390
    84     /* check handle & get filesize. */
    85     rc = DosQueryFileInfo (handle, FIL_STANDARD, &fsts3, sizeof(fsts3));
     91    /* check hFile & get filesize. */
     92#if OFF_MAX > LONG_MAX
     93    if (__pfnDosOpenL)
     94    {
     95        rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     96        fLarge = 1;
     97    }
     98    else
     99#endif
     100        rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
    86101    if (!rc)
    87102    {
    88         FILELOCK      FileLockDummy = {0, 0};
    89         FILELOCK      FileLock;
    90         PFILELOCK     pFLLock;
    91         PFILELOCK     pFLUnlock;
    92         ULONG         fAccess;
    93         ULONG         ulTimeout;
     103        ULONG       fAccess;
     104        int         fLock;
     105        ULONG       ulTimeout;
     106        off_t       cbFile;
     107        off_t       offStart;
     108        off_t       cbRange;
     109#if OFF_MAX > LONG_MAX
     110        if (fLarge)
     111            cbFile = info.fsts3L.cbFile;
     112        else
     113#endif
     114            cbFile = info.fsts3.cbFile;
     115
     116        /* range */
     117        cbRange = pflock->l_len ? pflock->l_len : OFF_MAX;
    94118
    95119        /* offset */
    96120        switch (pflock->l_whence)
    97121        {
    98             case SEEK_SET:  FileLock.lOffset = pflock->l_start; break;
    99             case SEEK_CUR:  FileLock.lOffset = tell (handle) + pflock->l_start; break;
    100             case SEEK_END:  FileLock.lOffset = fsts3.cbFile - pflock->l_start; break;
     122            case SEEK_SET:  offStart = pflock->l_start; break;
     123            case SEEK_CUR:  offStart = tell(hFile) + pflock->l_start; break;
     124            case SEEK_END:  offStart = cbFile - pflock->l_start; break;
    101125            default:
    102126                errno = EINVAL;
    103127                return -1;
    104128        }
    105         if (FileLock.lOffset < 0)
     129        if (    offStart < 0
     130            ||  cbRange + offStart < 0 )
    106131        {
    107132            errno = EINVAL;
    108133            return -1;
    109134        }
    110 
    111         /* range */
    112         FileLock.lRange = pflock->l_len ? pflock->l_len : LONG_MAX;
    113135
    114136        /* flags and order */
     
    117139        {
    118140            case F_UNLCK:
    119                 pFLLock   = &FileLockDummy;
    120                 pFLUnlock = &FileLock;
     141                fLock = 0;
    121142                break;
    122143
     
    124145                fAccess = 1; /* shared */
    125146            case F_WRLCK:
    126                 pFLLock   = &FileLock;
    127                 pFLUnlock = &FileLockDummy;
     147                fLock = 1;
    128148                break;
    129149
     
    140160
    141161        /* Do work. */
    142         rc = DosSetFileLocks (handle, pFLUnlock, pFLLock, ulTimeout, fAccess);
     162#if OFF_MAX > LONG_MAX
     163        if (__pfnDosSetFileLocksL)
     164        {
     165            FILELOCKL   aflock[2];
     166            memset(&aflock[(fLock + 1) & 1], 0, sizeof(aflock[0]));
     167            aflock[fLock].lOffset = offStart;
     168            aflock[fLock].lRange  = cbRange;
     169            rc = __pfnDosSetFileLocksL(hFile, &aflock[0], &aflock[1], ulTimeout, fAccess);
     170        }
     171        else
     172#endif
     173        {
     174            FILELOCK    aflock[2];
     175#if OFF_MAX > LONG_MAX
     176            if (    offStart > LONG_MAX
     177                ||  cbRange > LONG_MAX
     178                ||  offStart + cbRange > LONG_MAX
     179                )
     180              {
     181                errno = EOVERFLOW;
     182                return -1;
     183              }
     184#endif
     185            memset(&aflock[(fLock + 1) & 1], 0, sizeof(aflock[0]));
     186            aflock[fLock].lOffset = offStart;
     187            aflock[fLock].lRange  = cbRange;
     188
     189            rc = DosSetFileLocks(hFile, &aflock[0], &aflock[1], ulTimeout, fAccess);
     190        }
    143191    }
    144192
  • trunk/src/emx/src/lib/sys/__fstat.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/fstat.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/fstat.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   sys/__fstat.c (libc)  -- Copyright (c) 2003 by knut st. osmundsen
     3 */
    24
    35#include "libc-alias.h"
     
    911#include "syscalls.h"
    1012
    11 int __fstat (int handle, struct stat *buf)
     13int __fstat(int hFile, struct stat *pStat)
    1214{
    13   ULONG rc;
    14   ULONG htype, hflags;
    15   FILESTATUS3 info;
     15    ULONG rc;
     16    ULONG ulType;
     17    ULONG flFlags;
    1618
    17   memset (buf, 0, sizeof (*buf));
    18   rc = DosQueryHType (handle, &htype, &hflags);
    19   if (rc != 0)
     19    /*
     20     * Use query handle type to figure out the file type.
     21     */
     22    memset(pStat, 0, sizeof(*pStat));
     23    rc = DosQueryHType(hFile, &ulType, &flFlags);
     24    if (rc)
    2025    {
    21       _sys_set_errno (rc);
    22       return -1;
     26        _sys_set_errno(rc);
     27        return -1;
    2328    }
    24   switch (htype & 0xff)
     29    switch (ulType & 0xff)
    2530    {
    26     case 1:
    27       buf->st_mode = S_IFCHR;
    28       break;
    29     case 2:
    30       buf->st_mode = S_IFSOCK;
    31       break;
    32     default:
    33       buf->st_mode = S_IFREG;
    34       break;
     31        case FHT_CHRDEV:
     32            pStat->st_mode = S_IFCHR;
     33            break;
     34        case FHT_PIPE:
     35            pStat->st_mode = S_IFSOCK;
     36            break;
     37        default:
     38            pStat->st_mode = S_IFREG;
     39            break;
    3540    }
    36   if (buf->st_mode == S_IFREG)
     41
     42    if (pStat->st_mode == S_IFREG)
    3743    {
    38       rc = DosQueryFileInfo (handle, FIL_STANDARD, &info, sizeof (info));
    39       if (rc != 0)
     44        union
    4045        {
    41           _sys_set_errno (rc);
    42           return -1;
     46            FILESTATUS3     fsts3;
     47            FILESTATUS3L    fsts3L;
     48        } info;
     49    #if OFF_MAX > LONG_MAX
     50        int     fLarge = 0;
     51    #endif
     52
     53        /*
     54         * Get file info.
     55         */
     56#if OFF_MAX > LONG_MAX
     57        if (__pfnDosOpenL)
     58        {
     59            rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     60            fLarge = 1;
    4361        }
    44       buf->st_attr = info.attrFile;
    45       buf->st_size = info.cbFile;
    46       buf->st_reserved = 0;
    47       buf->st_mtime = _sys_p2t (info.ftimeLastWrite, info.fdateLastWrite);
    48       if (FTIMEZEROP (info.ftimeCreation) &&
    49           FDATEZEROP (info.fdateCreation))
    50         buf->st_ctime = buf->st_mtime;
    51       else
    52         buf->st_ctime = _sys_p2t (info.ftimeCreation, info.fdateCreation);
    53       if (FTIMEZEROP (info.ftimeLastAccess) &&
    54           FDATEZEROP (info.fdateLastAccess))
    55         buf->st_atime = buf->st_mtime;
    56       else
    57         buf->st_atime = _sys_p2t (info.ftimeLastAccess, info.fdateLastAccess);
    58       if (info.attrFile & 1)
    59         buf->st_mode |= (S_IREAD >> 6) * 0111;
    60       else
    61         buf->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     62        else
     63#endif
     64            rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
     65        if (rc)
     66        {
     67            _sys_set_errno (rc);
     68            return -1;
     69        }
     70
     71        /*
     72         * Format stats struct.
     73         *      We know the info struct layouts!
     74         *      Only cbFile, cbFileAlloc and attrFile need be accessed
     75         *      using the specific structure.
     76         */
     77        /* Times: FAT might not return create and access time. */
     78        pStat->st_mtime = _sys_p2t(info.fsts3.ftimeLastWrite, info.fsts3.fdateLastWrite);
     79        if (    FTIMEZEROP(info.fsts3.ftimeCreation)
     80            &&  FDATEZEROP(info.fsts3.fdateCreation))
     81            pStat->st_ctime = pStat->st_mtime;
     82        else
     83            pStat->st_ctime = _sys_p2t(info.fsts3.ftimeCreation, info.fsts3.fdateCreation);
     84        if (    FTIMEZEROP(info.fsts3.ftimeLastAccess)
     85            &&  FDATEZEROP(info.fsts3.fdateLastAccess))
     86            pStat->st_atime = pStat->st_mtime;
     87        else
     88            pStat->st_atime = _sys_p2t(info.fsts3.ftimeLastAccess, info.fsts3.fdateLastAccess);
     89
     90#if OFF_MAX > LONG_MAX
     91        if (fLarge)
     92        {
     93            pStat->st_size = info.fsts3L.cbFile;
     94            rc = info.fsts3L.attrFile;
     95        }
     96        else
     97#endif
     98        {
     99            pStat->st_size = info.fsts3.cbFile;
     100            rc = info.fsts3.attrFile;
     101        }
     102        pStat->st_attr = rc;
     103        if (rc & FILE_READONLY)
     104            pStat->st_mode |= (S_IREAD >> 6) * 0111;
     105        else
     106            pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
    62107    }
    63   else
     108    else
    64109    {
    65       buf->st_size = 0;
    66       rc = DosQueryFHState (handle, &hflags);
    67       if (rc != 0)
     110        pStat->st_size = 0;
     111        rc = DosQueryFHState(hFile, &flFlags);
     112        if (rc)
    68113        {
    69           _sys_set_errno (rc);
    70           return -1;
     114            _sys_set_errno (rc);
     115            return -1;
    71116        }
    72       if ((hflags & 7) == 0)
    73         buf->st_mode |= (S_IREAD >> 6) * 0111;
    74       else
    75         buf->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     117        if ((flFlags & 7) == OPEN_ACCESS_READONLY)
     118            pStat->st_mode |= (S_IREAD >> 6) * 0111;
     119        else
     120            pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
    76121    }
    77   buf->st_uid = 0;
    78   buf->st_gid = 0;
    79   buf->st_ino = _sys_ino++;
    80   if (_sys_ino == 0)
    81     _sys_ino = 1;
    82   buf->st_dev = 0;
    83   buf->st_rdev = 0;
    84   buf->st_nlink = 1;
    85   return 0;
     122
     123    /* default fake stuff */
     124    pStat->st_uid = 0;
     125    pStat->st_gid = 0;
     126    pStat->st_ino = _sys_ino++;
     127    if (_sys_ino == 0)
     128        _sys_ino = 1;
     129    pStat->st_dev = 0;
     130    pStat->st_rdev = 0;
     131    pStat->st_nlink = 1;
     132    pStat->st_reserved = 0;             /* what is this good for?!? */
     133    return 0;
    86134}
  • trunk/src/emx/src/lib/sys/__ftruncate.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/ftruncat.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/ftruncat.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   Copyright (c) 2003 Dimitry Froloff
     3   Copyright (c) 2003 knut st. osmundsen
     4 */
    25
    36#include "libc-alias.h"
    47#include <os2emx.h>
    58#include <emx/syscalls.h>
     9#include <limits.h>
     10#include <errno.h>
    611#include "syscalls.h"
    712
    8 int __ftruncate (int handle, long length)
     13int __ftruncate(int hFile, off_t cbFile)
    914{
    10   ULONG rc;
    11   FILESTATUS3 info;
     15    ULONG       rc;
     16    off_t       cbCur;
     17    union
     18    {
     19        FILESTATUS3     fsts3;
     20        FILESTATUS3L    fsts3L;
     21    } info;
    1222
    13   rc = DosQueryFileInfo (handle, FIL_STANDARD, &info, sizeof (info));
    14   if (rc != 0)
     23    /*
     24     * First step, figure out the current size.
     25     */
     26#if OFF_MAX > LONG_MAX
     27    if (__pfnDosOpenL)
    1528    {
    16       _sys_set_errno (rc);
    17       return -1;
     29        rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     30        cbCur = info.fsts3L.cbFile;
    1831    }
    19   if (info.cbFile > length)
     32    else
     33#endif
    2034    {
    21       rc = DosSetFileSize (handle, length);
    22       if (rc != 0)
     35        rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
     36        cbCur = info.fsts3.cbFile;
     37    }
     38    if (rc)
     39    {
     40        _sys_set_errno(rc);
     41        return -1;
     42    }
     43
     44
     45    /*
     46     * Is the file larger than the truncation size?
     47     * Then set the desired file size.
     48     */
     49    if (cbCur > cbFile)
     50    {
     51#if OFF_MAX > LONG_MAX
     52        if (__pfnDosSetFileSizeL)
     53            rc = __pfnDosSetFileSizeL(hFile, cbFile);
     54        else
    2355        {
    24           _sys_set_errno (rc);
    25           return -1;
     56            if (cbFile > __LONG_MAX)
     57            {
     58                errno = EOVERFLOW;
     59                return -1;
     60            }
     61            rc = DosSetFileSize(hFile, cbFile);
     62        }
     63#else
     64        rc = DosSetFileSize(hFile, cbFile);
     65#endif
     66        if (rc != 0)
     67        {
     68            _sys_set_errno(rc);
     69            return -1;
    2670        }
    2771    }
    28   return 0;
     72    return 0;
    2973}
  • trunk/src/emx/src/lib/sys/__init.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r731 r732  
    488488      __sigemptyset (&tp->signals[n].sa_mask);
    489489    }
    490   tp->fd.find_handle = HDIR_CREATE;
    491   tp->fd.find_next = NULL;
    492   tp->fd.find_count = 0;
    493 }
     490  tp->fd.hdir = HDIR_CREATE;
     491  tp->fd.cFiles = 0;
     492}
  • trunk/src/emx/src/lib/sys/__initdll.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /*
     1/* $Id$ */
     2/** @file
     3
    24    Dynamic library low-level initialization routine.
    35
     
    911*/
    1012
     13
     14/*******************************************************************************
     15*   Defined Constants And Macros                                               *
     16*******************************************************************************/
     17#define SYS_PRIVATE_HEAP_SIZE 0x100000
     18
     19/*******************************************************************************
     20*   Header Files                                                               *
     21*******************************************************************************/
    1122#include "libc-alias.h"
    1223#define INCL_DOS
     
    2132#include "syscalls.h"
    2233
    23 #define SYS_PRIVATE_HEAP_SIZE 0x100000
    24 
    25 extern int __init_environ(const char *pszEnv);
     34/*******************************************************************************
     35*   Global Variables                                                           *
     36*******************************************************************************/
    2637extern unsigned char _osminor;
    2738extern unsigned char _osmajor;
     39
     40
     41/*******************************************************************************
     42*   External Functions                                                         *
     43*******************************************************************************/
     44extern int __init_environ(const char *pszEnv);
     45extern void __init_largefileio(void) __attribute__((weak));
     46
    2847
    2948/**
     
    85104     * Let's try put it in high memory...
    86105     */
     106    /** @todo Redo this private heap stuff. */
    87107    rc = DosAllocMem(&_sys_private_heap, SYS_PRIVATE_HEAP_SIZE,
    88108                     _sys_virtual_address_limit
     
    113133
    114134    /*
     135     * Init long file I/O functions.
     136     * This is weak, so that it's only linked in when we're building with
     137     * large file suppoort enabled.
     138     */
     139    if (__init_largefileio)
     140        __init_largefileio();
     141
     142    /*
    115143     * Get current time for clock() for use as process startup time.
    116144     */
     
    118146    return 0;
    119147}
     148
  • trunk/src/emx/src/lib/sys/__lseek.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/lseek.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/lseek.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   Copyright (c) 2003 Dimitry Froloff
     3   Copyright (c) 2003 knut st. osmundsen
     4 */
    25
    36#include "libc-alias.h"
    47#include <os2emx.h>
    58#include <emx/syscalls.h>
     9#include <limits.h>
     10#include <errno.h>
    611#include "syscalls.h"
    712
    8 int __lseek (int handle, long offset, int origin)
     13off_t __lseek(int hFile, off_t off, int origin)
    914{
    10   ULONG rc;
    11   ULONG new;
     15    ULONG  rc;
     16    off_t   cbNew;
    1217
    13   rc = DosSetFilePtr (handle, offset, origin, &new);
    14   if (rc == 0)
    15     return (int)new;
    16   else
     18    if (origin == FILE_SECTOR)
    1719    {
    18       _sys_set_errno (rc);
    19       return -1;
     20        errno = EINVAL;
     21        return -1;
    2022    }
     23
     24#if OFF_MAX > LONG_MAX
     25    if (__pfnDosSetFilePtrL)
     26    {
     27        LONGLONG cbNewTmp;
     28        rc = __pfnDosSetFilePtrL(hFile, off, origin, &cbNewTmp);
     29        cbNew = cbNewTmp;
     30    }
     31    else
     32    {
     33        ULONG cbNewTmp;
     34        if (off > LONG_MAX || off < LONG_MIN)
     35        {
     36            errno = EOVERFLOW;
     37            return -1;
     38        }
     39        rc = DosSetFilePtr(hFile, off, origin, &cbNewTmp);
     40        cbNew = cbNewTmp;
     41    }
     42#else
     43    {
     44        ULONG cbNewTmp;
     45        rc = DosSetFilePtr(hFile, off, origin, &cbNewTmp);
     46        cbNew = cbNewTmp;
     47    }
     48#endif
     49
     50    if (rc)
     51    {
     52        _sys_set_errno (rc);
     53        return -1;
     54    }
     55
     56    return cbNew;
    2157}
     58
  • trunk/src/emx/src/lib/sys/__open.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/open.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/open.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   Copyright (c) 2003 Dimitry Froloff
     3   Copyright (c) 2003 knut st. osmundsen
     4 */
    25
    36#include "libc-alias.h"
     
    69#include <string.h>
    710#include <errno.h>
     11#include <limits.h>
    812#include <emx/syscalls.h>
    913#include "syscalls.h"
    1014
    11 int __open (const char *name, int flags, unsigned long size)
     15int __open(const char *pszFile, int flags, off_t cbInitial)
    1216{
    13   ULONG rc;
    14   ULONG open_mode, attr, action, open_flag;
    15   HFILE handle;
    16   int fail_errno;
     17    ULONG   rc;
     18    ULONG   flOpenMode;
     19    ULONG   flOpenFlags;
     20    ULONG   flAttr;
     21    ULONG   ulAction;
     22    HFILE   hFile;
     23    int     failed_open_errno;
    1724
    18   /* Interpret "/dev/null" as the name of the null device "NUL".
    19      Interpret "/dev/tty" as the name of the console device "CON". */
     25    /*
     26     * Interpret "/dev/null" as the pszFile of the null device "NUL".
     27     * Interpret "/dev/tty" as the pszFile of the console device "CON".
     28     */
     29    if (!strcmp(pszFile, "/dev/null"))
     30        pszFile = "nul";
     31    else if (!strcmp(pszFile, "/dev/tty"))
     32        pszFile = "con";
    2033
    21   if (strcmp (name, "/dev/null") == 0)
    22     name = "nul";
    23   else if (strcmp (name, "/dev/tty") == 0)
    24     name = "con";
     34    /*
     35     * Extract the access mode and sharing mode bits.
     36     */
     37    flOpenMode = flags & 0x77;
    2538
    26   /* Extract the access mode and sharing mode bits. */
     39    /*
     40     * File O_NOINHERIT and O_SYNC.
     41     */
     42    if (flags & _SO_NOINHERIT)
     43        flOpenMode |= OPEN_FLAGS_NOINHERIT;
     44    if (flags & _SO_SYNC)
     45        flOpenMode |= OPEN_FLAGS_WRITE_THROUGH;
    2746
    28   open_mode = flags & 0x77;
     47    /*
     48     * Extract the file flAttribute bits.
     49     */
     50    flAttr = (flags >> 8) & 0xff;
     51    if (_sys_umask & 0200)
     52        flAttr |= FILE_READONLY;
    2953
    30   /* Handle O_NOINHERIT and O_SYNC. */
     54    /*
     55     * Translate ERROR_OPEN_FAILED to ENOENT unless O_EXCL is set (see below).
     56     */
     57    failed_open_errno = ENOENT;
    3158
    32   if (flags & _SO_NOINHERIT)
    33     open_mode |= OPEN_FLAGS_NOINHERIT;
    34   if (flags & _SO_SYNC)
    35     open_mode |= OPEN_FLAGS_WRITE_THROUGH;
     59    /*
     60     * Compute `flOpenFlags' depending on `flags'.  Note that _SO_CREAT is
     61     * set for O_CREAT.
     62     */
     63    if (flags & _SO_CREAT)
     64    {
     65        if (flags & _SO_EXCL)
     66        {
     67            flOpenFlags = OPEN_ACTION_FAIL_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
     68            failed_open_errno = EEXIST;
     69        }
     70        else if (flags & _SO_TRUNC)
     71            flOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
     72        else
     73            flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
     74    }
     75    else if (flags & _SO_TRUNC)
     76        flOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
     77    else
     78        flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
    3679
    37   /* Extract the file attribute bits. */
     80    if (!(flags & _SO_SIZE))
     81        cbInitial = 0;
    3882
    39   attr = (flags >> 8) & 0xff;
    40   if (_sys_umask & 0200)
    41     attr |= 1;
     83    /*
     84     * Try to open the file.
     85     */
     86#if OFF_MAX > LONG_MAX
     87    if (__pfnDosOpenL)
     88    {
     89        LONGLONG cbInitialTmp = cbInitial;
     90        rc = __pfnDosOpenL(pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
     91    }
     92    else
     93    {
     94        ULONG cbInitialTmp = (ULONG)cbInitial;
     95        if (cbInitial > LONG_MAX)
     96        {
     97            errno = EOVERFLOW;
     98            return -1;
     99        }
     100        rc = DosOpen(pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
     101    }
     102#else
     103    {
     104        ULONG cbInitialTmp = cbInitial;
     105        rc = DosOpen(pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
     106    }
     107#endif
    42108
    43   /* Translate ERROR_OPEN_FAILED to ENOENT unless O_EXCL is set (see
    44      below). */
    45 
    46   fail_errno = ENOENT;
    47 
    48   /* Compute `open_flag' depending on `flags'.  Note that _SO_CREAT is
    49      set for O_CREAT. */
    50 
    51   if (flags & _SO_CREAT)
     109    /*
     110     * Handle any errors.
     111     */
     112    if (rc)
    52113    {
    53       if (flags & _SO_EXCL)
    54         {
    55           open_flag = OPEN_ACTION_FAIL_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
    56           fail_errno = EEXIST;
    57         }
    58       else if (flags & _SO_TRUNC)
    59         open_flag = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
    60       else
    61         open_flag = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
     114        if (rc == ERROR_OPEN_FAILED)
     115            errno = failed_open_errno;
     116        else
     117            _sys_set_errno(rc);
     118        return -1;
    62119    }
    63   else if (flags & _SO_TRUNC)
    64     open_flag = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
    65   else
    66     open_flag = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
    67 
    68   if (!(flags & _SO_SIZE))
    69     size = 0;
    70 
    71   /* Try to open the file and handle errors. */
    72 
    73   rc = DosOpen (name, &handle, &action, size, attr, open_flag, open_mode,
    74                 NULL);
    75   if (rc == ERROR_OPEN_FAILED)
    76     {
    77       errno = fail_errno;
    78       return -1;
    79     }
    80   if (rc != 0)
    81     {
    82       _sys_set_errno (rc);
    83       return -1;
    84     }
    85   return handle;
     120    return hFile;
    86121}
  • trunk/src/emx/src/lib/sys/__stat.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/stat.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/stat.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   sys/__stat.c (libc)  -- Copyright (c) 2003 by knut st. osmundsen
     3 */
    24
    35#include "libc-alias.h"
     
    1012#include "syscalls.h"
    1113
    12 int __stat (const char *name, struct stat *buf)
     14int __stat(const char *pszPath, struct stat *pStat)
    1315{
    14   ULONG rc;
    15   FILESTATUS3 info;
     16    ULONG   rc;
     17    union
     18    {
     19        FILESTATUS3     fsts3;
     20        FILESTATUS3L    fsts3L;
     21    } info;
     22#if OFF_MAX > LONG_MAX
     23    int     fLarge = 0;
     24#endif
    1625
    17   memset (buf, 0, sizeof (*buf));
    18   if ((name[0] == '/' || name[0] == '\\') && strlen (name) >= 6 &&
    19       memicmp (name+1, "pipe", 4) == 0 && (name[5] == '/' || name[5] == '\\'))
     26    /*
     27     * Validate input, refusing named pipes.
     28     */
     29    memset(pStat, 0, sizeof(*pStat));
     30    if (    (pszPath[0] == '/' || pszPath[0] == '\\')
     31        &&  !strnicmp(pszPath+1, "pipe", 4)
     32        &&  (pszPath[5] == '/' || pszPath[5] == '\\'))
    2033    {
    21       errno = ENOENT;
    22       return -1;
     34        errno = ENOENT;
     35        return -1;
    2336    }
    24   rc = DosQueryPathInfo (name, FIL_STANDARD, &info, sizeof (info));
    25   if (rc != 0)
     37
     38    /*
     39     * Get path info.
     40     */
     41#if OFF_MAX > LONG_MAX
     42    if (__pfnDosOpenL)
    2643    {
    27       _sys_set_errno (rc);
    28       return -1;
     44        rc = DosQueryPathInfo(pszPath, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     45        fLarge = 1;
    2946    }
    30   buf->st_attr = info.attrFile;
    31   buf->st_reserved = 0;
    32   buf->st_mtime = _sys_p2t (info.ftimeLastWrite, info.fdateLastWrite);
    33   if (FTIMEZEROP (info.ftimeCreation) &&
    34       FDATEZEROP (info.fdateCreation))
    35     buf->st_ctime = buf->st_mtime;
    36   else
    37     buf->st_ctime = _sys_p2t (info.ftimeCreation, info.fdateCreation);
    38   if (FTIMEZEROP (info.ftimeLastAccess) &&
    39       FDATEZEROP (info.fdateLastAccess))
    40     buf->st_atime = buf->st_mtime;
    41   else
    42     buf->st_atime = _sys_p2t (info.ftimeLastAccess, info.fdateLastAccess);
    43   if (info.attrFile & 0x10)     /* directory */
     47    else
     48#endif
     49        rc = DosQueryPathInfo(pszPath, FIL_STANDARD, &info, sizeof(info.fsts3));
     50    if (rc)
    4451    {
    45       buf->st_mode = S_IFDIR;
    46       buf->st_mode |= ((S_IREAD|S_IWRITE|S_IEXEC) >> 6) * 0111;
    47       buf->st_size = 0;
     52        _sys_set_errno(rc);
     53        return -1;
    4854    }
    49   else
     55
     56    /*
     57     * Format stats struct.
     58     *      We know the info struct layouts!
     59     *      Only cbFile, cbFileAlloc and attrFile need be accessed
     60     *      using the specific structure.
     61     */
     62    /* Times: FAT might not return create and access time. */
     63    pStat->st_mtime = _sys_p2t(info.fsts3.ftimeLastWrite, info.fsts3.fdateLastWrite);
     64    if (   FTIMEZEROP(info.fsts3.ftimeCreation)
     65        && FDATEZEROP(info.fsts3.fdateCreation))
     66        pStat->st_ctime = pStat->st_mtime;
     67    else
     68        pStat->st_ctime = _sys_p2t(info.fsts3.ftimeCreation, info.fsts3.fdateCreation);
     69    if (   FTIMEZEROP(info.fsts3.ftimeLastAccess)
     70        && FDATEZEROP(info.fsts3.fdateLastAccess))
     71        pStat->st_atime = pStat->st_mtime;
     72    else
     73        pStat->st_atime = _sys_p2t(info.fsts3.ftimeLastAccess, info.fsts3.fdateLastAccess);
     74
     75#if OFF_MAX > LONG_MAX
     76    rc = fLarge ? info.fsts3L.attrFile : info.fsts3.attrFile;
     77#else
     78    rc = info.fsts3.attrFile;
     79#endif
     80    pStat->st_attr = rc;
     81    if (rc & FILE_DIRECTORY)
    5082    {
    51       buf->st_size = info.cbFile;
    52       buf->st_mode = S_IFREG;
    53       if (info.attrFile & 1)
    54         buf->st_mode |= (S_IREAD >> 6) * 0111;
    55       else
    56         buf->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     83        /* directory */
     84        pStat->st_mode = S_IFDIR;
     85        pStat->st_mode |= ((S_IREAD|S_IWRITE|S_IEXEC) >> 6) * 0111;
     86        pStat->st_size = 0;
    5787    }
    58   buf->st_uid = 0;
    59   buf->st_gid = 0;
    60   buf->st_ino = _sys_ino++;
    61   if (_sys_ino == 0)
    62     _sys_ino = 1;
    63   buf->st_dev = 0;
    64   buf->st_rdev = 0;
    65   buf->st_nlink = 1;
    66   return 0;
     88    else
     89    {
     90#if OFF_MAX > LONG_MAX
     91        if (fLarge)
     92            pStat->st_size = info.fsf3L.cbFile;
     93        else
     94#endif
     95            pStat->st_size = info.fsts3.cbFile;
     96        pStat->st_mode = S_IFREG;
     97        if (rc & FILE_READONLY)
     98            pStat->st_mode |= (S_IREAD >> 6) * 0111;
     99        else
     100            pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     101    }
     102    /* default fake stuff */
     103    pStat->st_uid = 0;
     104    pStat->st_gid = 0;
     105    pStat->st_ino = _sys_ino++;
     106    if (_sys_ino == 0)
     107        _sys_ino = 1;
     108    pStat->st_dev = 0;
     109    pStat->st_rdev = 0;
     110    pStat->st_nlink = 1;
     111    pStat->st_reserved = 0;             /* what is this good for?!? */
     112    return 0;
    67113}
  • trunk/src/emx/src/lib/sys/filefind.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r731 r732  
    1 /* sys/filefind.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/filefind.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   sys/filefind.c (libc)    -- Copyright (c) 2003 by knut st. osmundsen
     3*/
    24
    35#include "libc-alias.h"
    46#include <string.h>
    57#include <errno.h>
     8#include <limits.h>
     9#define INCL_BASE
    610#include <os2emx.h>
    711#include <emx/syscalls.h>
    812#include "syscalls.h"
    913
    10 /* Close the directory handle. */
    11 
    12 static void find_close (struct find_data *fd)
    13 {
    14   if (fd->find_handle != HDIR_CREATE)
    15     {
    16       DosFindClose (fd->find_handle);
    17       fd->find_handle = HDIR_CREATE;
    18     }
    19   fd->find_count = 0;
    20   fd->find_next = NULL;
     14/**
     15 * Close a directory find session.
     16 * @param   pFD     The directory find data.
     17 */
     18static void find_close(struct find_data *pFD)
     19{
     20    if (pFD->hdir != HDIR_CREATE)
     21    {
     22        DosFindClose(pFD->hdir);
     23        pFD->hdir = HDIR_CREATE;
     24    }
     25    pFD->cFiles = 0;
     26    pFD->pchNext = NULL;
    2127}
    2228
     
    2430   move to the next one. */
    2531
    26 static int find_conv (struct find_data *fd, struct _find *fp)
    27 {
    28   const FILEFINDBUF3 *src;
    29 
    30   /* Check if there are any entries.  Close the handle and return
    31      ENOENT if there are no entries.  (Checking SRC is redundant.) */
    32 
    33   src = fd->find_next;
    34   if (fd->find_count < 1 || src == NULL)
    35     {
    36       find_close (fd);
    37       errno = ENOENT;
    38       return -1;
    39     }
    40 
    41   /* Fill-in target object. */
    42 
    43   fp->attr = (unsigned char)src->attrFile;
    44   fp->time = XUSHORT (src->ftimeLastWrite);
    45   fp->date = XUSHORT (src->fdateLastWrite);
    46   fp->size_lo = (unsigned short)(src->cbFile & 0xffff);
    47   fp->size_hi = (unsigned short)(src->cbFile >> 16);
    48   strcpy (fp->name, src->achName);
    49 
    50   /* Move to the next entry. */
    51 
    52   if (src->oNextEntryOffset == 0)
    53     {
    54       fd->find_next = NULL;
    55       fd->find_count = 0;
    56     }
    57   else
    58     {
    59       fd->find_next = (FILEFINDBUF3 *)((char *)src + src->oNextEntryOffset);
    60       fd->find_count -= 1;
    61     }
    62 
    63   return 0;
    64 }
    65 
    66 
    67 int __findfirst (const char *name, int attr, struct _find *fp)
    68 {
    69   ULONG rc;
    70   struct find_data *fd;
    71 
    72   fd = &SYS_THREAD->fd;
    73 
    74   if (fd->find_handle != HDIR_CREATE)
    75     {
    76       /* Closing the handle is not strictly required as DosFindFirst
    77          can reuse an open handle.  However, this simplifies error
    78          handling below (will DosFindFirst close the handle on error
    79          if it is open?). */
    80 
    81       DosFindClose (fd->find_handle);
    82       fd->find_handle = HDIR_CREATE;
    83     }
    84 
    85   fd->find_count = FIND_COUNT;
    86   rc = DosFindFirst (name, &fd->find_handle, attr & 0x37,
    87                      &fd->find_buf[0], sizeof (fd->find_buf),
    88                      &fd->find_count, FIL_STANDARD);
    89   if (rc != 0)
    90     {
    91       fd->find_handle = HDIR_CREATE; /* Perhaps modified by DosFindFirst */
    92       fd->find_count = 0;
    93       fd->find_next = NULL;
    94       _sys_set_errno (rc);
    95       return -1;
    96     }
    97   fd->find_next = &fd->find_buf[0];
    98   return find_conv (fd, fp);
    99 }
    100 
    101 
    102 int __findnext (struct _find *fp)
    103 {
    104   ULONG rc;
    105   struct find_data *fd;
    106 
    107   fd = &SYS_THREAD->fd;
    108   if (fd->find_count < 1)
    109     {
    110       fd->find_count = FIND_COUNT;
    111       rc = DosFindNext (fd->find_handle, &fd->find_buf[0],
    112                         sizeof (fd->find_buf), &fd->find_count);
    113       if (rc != 0)
     32/**
     33 * Build a 'struct _find' from the next file in the directory find data.
     34 * @returns 0 on success.
     35 * @returns -1 on failure, ENOENT as errno.
     36 * @param   pFD     The directory find data.
     37 */
     38static int find_conv(struct find_data *pFD, struct _find *fp)
     39{
     40    union
     41    {
     42        const char             *pch;
     43        const FILEFINDBUF3     *pFindbuf3;
     44        const FILEFINDBUF3L    *pFindbuf3L;
     45    } u;
     46    u.pch = pFD->pchNext;
     47
     48    /*
     49     * If there ain't any entries, flag ENOENT error, clean up and
     50     * return failure.
     51     */
     52    if (!pFD->cFiles)
     53    {
     54        find_close(pFD);
     55        errno = ENOENT;
     56        return -1;
     57    }
     58
     59    /*
     60     * Fill-in target object.
     61     *  About the find structure we know that these fields are not the same
     62     *  in the two versions:
     63     *      cbFile, cbFileAlloc, attrFile, cchName, achName.
     64     */
     65    fp->time = XUSHORT(u.pFindbuf3->ftimeLastWrite);
     66    fp->date = XUSHORT(u.pFindbuf3->fdateLastWrite);
     67#if OFF_MAX > LONG_MAX
     68    if (pFD->fType == FIL_STANDARDL)
     69    {
     70        fp->cbFile = u.pFindbuf3L->cbFile;
     71        fp->attr   = (unsigned char)u.pFindbuf3L->attrFile;
     72        strcpy(fp->szName, &u.pFindbuf3L->achName[0]);
     73    }
     74    else
     75#endif
     76    {
     77        fp->cbFile = u.pFindbuf3->cbFile;
     78        fp->attr   = (unsigned char)u.pFindbuf3->attrFile;
     79        strcpy(fp->szName, &u.pFindbuf3->achName[0]);
     80    }
     81
     82    /*
     83     * Next entry.
     84     */
     85    if (pFD->cFiles && u.pFindbuf3->oNextEntryOffset)
     86    {
     87        pFD->pchNext = u.pch + u.pFindbuf3->oNextEntryOffset;
     88        pFD->cFiles--;
     89    }
     90    else
     91        pFD->cFiles = 0;
     92
     93    return 0;
     94}
     95
     96
     97/**
     98 * Start a directory find session.
     99 * It's only possible to perform one such session per thread. A call to this
     100 * function will terminate the previous one.
     101 *
     102 * @returns 0 on success
     103 * @returns -1 on failure and errno set appropriately.
     104 * @param   pszName Search pattern. Usually "<somepath>\\*"
     105 * @param   attr    File attributes to include in the search.
     106 *                  If 0 files with any attributes may be included.
     107 * @param   fp      Where to put the data on the first file found.
     108 */
     109int __findfirst(const char *pszName, int attr, struct _find *fp)
     110{
     111    ULONG               rc;
     112    struct find_data   *pFD = &SYS_THREAD->fd;
     113
     114    /*
     115     * Cleanup any open find sessions first.
     116     */
     117    if (pFD->hdir != HDIR_CREATE)
     118    {
     119        /* Closing the handle is not strictly required as DosFindFirst
     120           can reuse an open handle.  However, this simplifies error
     121           handling below (will DosFindFirst close the handle on error
     122           if it is open?). */
     123        DosFindClose(pFD->hdir);
     124        pFD->hdir = HDIR_CREATE;
     125    }
     126
     127    /*
     128     * Start file enumeration.
     129     */
     130    pFD->cFiles = 30; /* !! Careful with this number! Wrong values can trigger stupid bugs. */
     131#if OFF_MAX > LONG_MAX
     132    pFD->fType = __pfnDosOpenL ? FIL_STANDARDL : FIL_STANDARD;
     133#else
     134    pFD->fType = FIL_STANDARD;
     135#endif
     136    rc = DosFindFirst(pszName,
     137                      &pFD->hdir,
     138                      attr & (FILE_NORMAL | FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED),
     139                      &pFD->achBuffer[0],
     140                      sizeof(pFD->achBuffer),
     141                      &pFD->cFiles,
     142                      pFD->fType);
     143    if (rc)
     144    {
     145        pFD->hdir = HDIR_CREATE; /* Perhaps modified by DosFindFirst */
     146        pFD->cFiles = 0;
     147        pFD->pchNext = NULL;
     148        _sys_set_errno(rc);
     149        return -1;
     150    }
     151    pFD->pchNext = &pFD->achBuffer[0];
     152    return find_conv(pFD, fp);
     153}
     154
     155
     156/**
     157 * Get the next file in the current directory find session.
     158 * It's only possible to perform one such session per thread. A call to this
     159 * function will terminate the previous one.
     160 *
     161 * @returns 0 on success
     162 * @returns -1 on failure and errno set appropriately.
     163 * @param   pszName Search pattern. Usually "<somepath>\\*"
     164 * @param   attr    File attributes to include in the search.
     165 *                  If 0 files with any attributes may be included.
     166 * @param   fp      Where to put the data on the first file found.
     167 */
     168int __findnext(struct _find *fp)
     169{
     170    ULONG               rc;
     171    struct find_data   *pFD = &SYS_THREAD->fd;
     172
     173    /*
     174     * Check incoming.
     175     */
     176    if (pFD->hdir == HDIR_CREATE)
     177    {
     178        errno = EINVAL;
     179        return -1;
     180    }
     181
     182    /*
     183     * Do we need to fetch more files?
     184     */
     185    if (!pFD->cFiles)
     186    {
     187        pFD->cFiles = 30; /* !! Careful with this number! Wrong values can trigger stupid bugs. */
     188        rc = DosFindNext(pFD->hdir, &pFD->achBuffer[0], sizeof(pFD->achBuffer), &pFD->cFiles);
     189        if (rc)
    114190        {
    115           find_close (fd);
    116           _sys_set_errno (rc);
    117           return -1;
     191            find_close(pFD);
     192            _sys_set_errno(rc);
     193            return -1;
    118194        }
    119       fd->find_next = &fd->find_buf[0];
    120     }
    121 
    122   return find_conv (fd, fp);
    123 }
     195        pFD->pchNext = &pFD->achBuffer[0];
     196    }
     197
     198    return find_conv(pFD, fp);
     199}
     200
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r731 r732  
    1 /* sys/syscalls.h (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/syscalls.h (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2   sys/filefind.c (libc)    -- Copyright (c) 2003 by Andrew Zabolotny
     3   sys/filefind.c (libc)    -- Copyright (c) 2003 by Knut St. Osmundsen
     4 */
    25
    36#include "libc-alias.h"
     
    2427
    2528#define XUSHORT(x) (*(USHORT *)&(x))
    26 
    27 /* Fetch this many FILEFINDBUF3 entries at once with DosFindFirst and
    28    DosFindNext. */
    29 
    30 #define FIND_COUNT      4
    3129
    3230/* Maximum number of heap objects (16 = 512 / 32). */
     
    8179#if defined (_OS2EMX_H)
    8280
    83 #define FTIMEZEROP(x) (*(USHORT *)&(x) == 0)
    84 #define FDATEZEROP(x) (*(USHORT *)&(x) == 0)
     81/** @group Large File Support - API pointers.
     82 * Test if the function pointer is set before calling it.
     83 * For APIs which take a structure level parameter, check __pfnDosOpenL.
     84 * @{ */
     85extern ULONG (* _System __pfnDosOpenL)(PCSZ pszFileName, PHFILE phFile,
     86    PULONG pulAction, LONGLONG llFileSize, ULONG ulAttribute, ULONG ulOpenFlags,
     87    ULONG ulOpenMode, PEAOP2 pEABuf);
     88extern ULONG (* _System __pfnDosSetFilePtrL)(HFILE hFile, LONGLONG llOffset,
     89    ULONG ulOrigin, PLONGLONG pllPos);
     90extern ULONG (* _System __pfnDosSetFileSizeL)(HFILE hFile, LONGLONG cbSize);
     91extern ULONG (* _System __pfnDosSetFileLocksL)(HFILE hFile,
     92    __const__ FILELOCKL *pflUnlock, __const__ FILELOCKL *pflLock,
     93    ULONG ulTimeout, ULONG flFlags);
     94/** @} */
    8595
     96
     97/** Test if a DOS/OS2 file time is zero. */
     98#define FTIMEZEROP(x) (*(PUSHORT)&(x) == 0)
     99/** Test if a DOS/OS2 file date is zero. */
     100#define FDATEZEROP(x) (*(PUSHORT)&(x) == 0)
     101
     102/** Directory find data entry.
     103 * Used by __findfirst() and __findnext(). */
    86104struct find_data
    87105{
    88   HDIR find_handle;
    89   ULONG find_count;
    90   FILEFINDBUF3 find_buf[FIND_COUNT];
    91   const FILEFINDBUF3 *find_next;
     106    /** Directory handle. HDIR_CREATE if no session opened. */
     107    HDIR        hdir;
     108    /** Type of buffer content. FIL_STANDARDL or FIL_STANDARD,
     109     * i.e. FILEFINDBUF3 or FILEFINDBUF3L. */
     110    ULONG       fType;
     111    /** Number of files left in the buffer. */
     112    ULONG       cFiles;
     113    /** Pointer to the next entry. Don't test on this, test on cFiles! */
     114    const char *pchNext;
     115    /** Buffer. */
     116    char        achBuffer[2048];
    92117};
    93118
     
    152177ULONG _sys_shrink_heap_by (ULONG decr, ULONG sbrk_model);
    153178ULONG _sys_shrink_heap_obj_by (ULONG decr);
     179
  • trunk/src/emx/version.smak

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r731 r732  
    44VH = 0
    55# Middle part of version number
    6 VM = 3
     6VM = 4
    77# Low part of version number
    88VL = 0
Note: See TracChangeset for help on using the changeset viewer.