Message-ID: <3854EB26.B9DCE883@softhome.net> Date: Mon, 13 Dec 1999 14:48:38 +0200 From: Laurynas Biveinis X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 To: Eli Zaretskii , DJGPP Workers Subject: Re: The 4th symlink patch References: Content-Type: multipart/mixed; boundary="------------66128BF32BF64414F1DBC7A2" Reply-To: djgpp-workers AT delorie DOT com This is a multi-part message in MIME format. --------------66128BF32BF64414F1DBC7A2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii wrote: > Does this mean that there's no lstat.txh at all? I don't see it in > your last set of patches. There is, it just managed to get out of the last patch. It is basically stat.txt with one sentence added. Laurynas Biveinis ---------------------- --------------66128BF32BF64414F1DBC7A2 Content-Type: text/plain; charset=us-ascii; name="lstat.txh" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="lstat.txh" @node lstat, io @subheading Syntax @example #include int lstat(const char *file, struct stat *sbuf); @end example @subheading Description This function obtains the status of the file @var{file} and stores it in @var{sbuf}, which has this structure: @example struct stat @{ time_t st_atime; /* time of last modification */ time_t st_ctime; /* '' */ dev_t st_dev; /* The drive number (0 = a:) */ gid_t st_gid; /* getgid() */ ino_t st_ino; /* starting cluster or a unique identifier */ mode_t st_mode; /* file mode - S_IF* and S_IRUSR/S_IWUSR */ time_t st_mtime; /* '' */ nlink_t st_nlink; /* 2 + number of subdirs, or 1 for files */ off_t st_size; /* size of file in bytes */ off_t st_blksize; /* the size of transfer buffer */ uid_t st_uid; /* getuid() */ @}; @end example It does not follow DJGPP symlinks, so you get the info about symlink file itself in such case. @subheading Return Value Zero on success, nonzero on failure (and @var{errno} set). @subheading Portability @portability !ansi, posix @subheading Example @example struct stat s; lstat("data.txt", &s); if (S_ISDIR(s.st_mode)) printf("is directory\n"); @end example @subheading Implementation Notes Supplying a 100% Unix-compatible @code{f?stat()} functions under DOS is an implementation nightmare. The following notes describe some of the obscure points specific to their behavior in DJGPP. 1. The @samp{drive} for character devices (like @code{con}, @code{/dev/null} and others is returned as -1. For drives networked by Novell Netware, it is returned as -2. 2. The starting cluster number of a file serves as its inode number. For files whose starting cluster number is inaccessible (empty files, files on networked drives, etc.) the @code{st_inode} field will be @cite{invented} in a way which guarantees that no two different files will get the same inode number (thus it is unique). This invented inode will also be different from any real cluster number of any local file. However, only on plain DOS, and only for local, non-empty files/directories the inode is guaranteed to be consistent between @code{lstat}, @code{stat} and @code{fstat} function calls. 3. The WRITE access mode bit is set only for the user (unless the file is read-only, hidden or system). EXECUTE bit is set for directories, files which can be executed from the DOS prompt (batch files, .com, .dll and .exe executables) or run by @code{go32-v2}. 4. Size of directories is reported as the number of its files (sans `.' and `..' entries) multiplied by 32 bytes (the size of directory entry). On FAT filesystems that support the LFN API (such as Windows 9X), the reported size of the directory accounts for additional space used to store the long file names. 5. Time stamp for root directories is taken from the volume label entry, if that's available; otherwise, it is reported as 1-Jan-1980. 6. The variable @code{_djstat_flags} (@pxref{_djstat_flags}) controls what hard-to-get fields of @code{struct stat} are needed by the application. 7. @code{lstat} should not be used to get an up-to-date info about a file which is open and has been written to, because @code{lstat} will only return correct data after the file is closed. Use @code{fstat} (@pxref{fstat}) while the file is open. Alternatively, you can call @code{fflush} and @code{fsync} to make the OS flush all the file's data to the disk, before calling @code{lstat}. 8. The number of links @code{st_nlink} is always 1 for files other than directories. For directories, it is the number of subdirectories plus 2. This is so that programs written for Unix that depend on this to optimize recursive traversal of the directory tree, will still work. --------------66128BF32BF64414F1DBC7A2--