diff --git a/contrib/sdk/sources/newlib/libc/Makefile b/contrib/sdk/sources/newlib/libc/Makefile index 40378655f8..0b565dff62 100644 --- a/contrib/sdk/sources/newlib/libc/Makefile +++ b/contrib/sdk/sources/newlib/libc/Makefile @@ -15,7 +15,7 @@ LIBC_INCLUDES = $(LIBC_TOPDIR)/include NAME:= libc -DEFINES:= -D_IEEE_LIBM +DEFINES:= -D_IEEE_LIBM -DHAVE_RENAME INCLUDES:= -I $(LIBC_INCLUDES) @@ -97,27 +97,29 @@ CORE_SRCS:= \ locale/locale.c \ locale/lctype.c \ locale/ldpart.c \ + reent/closer.c \ + reent/fstatr.c \ + reent/getreent.c \ + reent/gettimeofdayr.c \ reent/impure.c \ reent/init_reent.c \ - reent/getreent.c \ - reent/mutex.c \ - reent/gettimeofdayr.c \ reent/isattyr.c \ - reent/openr.c \ - reent/closer.c \ reent/linkr.c \ - reent/readr.c \ reent/lseekr.c \ - reent/fstatr.c \ - reent/writer.c \ + reent/mutex.c \ + reent/openr.c \ + reent/readr.c \ + reent/renamer.c \ + reent/statr.c \ reent/timesr.c \ reent/unlinkr.c \ + reent/writer.c \ search/qsort.c \ search/bsearch.c \ signal/signal.c \ + sys/access.c \ sys/close.c \ sys/create.c \ - sys/delete.c \ sys/errno.c \ sys/finfo.c \ sys/fsize.c \ @@ -130,6 +132,7 @@ CORE_SRCS:= \ sys/lseek.c \ sys/open.c \ sys/read.c \ + sys/_rename.c \ sys/stat.c \ sys/unlink.c \ sys/write.c \ @@ -267,11 +270,13 @@ STDIO_SRCS= \ fwrite.c \ fvwrite.c \ fwalk.c \ + mktemp.c \ putc.c \ puts.c \ refill.c \ rget.c \ remove.c \ + rename.c \ rewind.c \ setvbuf.c \ stdio.c \ diff --git a/contrib/sdk/sources/newlib/libc/reent/statr.c b/contrib/sdk/sources/newlib/libc/reent/statr.c new file mode 100644 index 0000000000..9ad2bb209f --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/reent/statr.c @@ -0,0 +1,68 @@ +/* Reentrant versions of stat system call. This implementation just + calls the stat system call. */ + +#include +#include +#include +#include <_syslist.h> + +/* Some targets provides their own versions of these functions. Those + targets should define REENTRANT_SYSCALLS_PROVIDED in + TARGET_CFLAGS. */ + +#ifdef _REENT_ONLY +#ifndef REENTRANT_SYSCALLS_PROVIDED +#define REENTRANT_SYSCALLS_PROVIDED +#endif +#endif + +#ifdef REENTRANT_SYSCALLS_PROVIDED + +int _dummy_stat_syscalls = 1; + +#else + +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; + +/* +FUNCTION + <<_stat_r>>---Reentrant version of stat + +INDEX + _stat_r + +ANSI_SYNOPSIS + #include + int _stat_r(struct _reent *<[ptr]>, + const char *<[file]>, struct stat *<[pstat]>); + +TRAD_SYNOPSIS + #include + int _stat_r(<[ptr]>, <[file]>, <[pstat]>) + struct _reent *<[ptr]>; + char *<[file]>; + struct stat *<[pstat]>; + +DESCRIPTION + This is a reentrant version of <>. It + takes a pointer to the global data block, which holds + <>. +*/ + +int +_DEFUN (_stat_r, (ptr, file, pstat), + struct _reent *ptr _AND + _CONST char *file _AND + struct stat *pstat) +{ + int ret; + + errno = 0; + if ((ret = _stat (file, pstat)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; +} + +#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/mktemp.c b/contrib/sdk/sources/newlib/libc/stdio/mktemp.c new file mode 100644 index 0000000000..ecbc7afea9 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/mktemp.c @@ -0,0 +1,385 @@ +/* + * Copyright (c) 1987 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that: (1) source distributions retain this entire copyright + * notice and comment, and (2) distributions including binaries display + * the following acknowledgement: ``This product includes software + * developed by the University of California, Berkeley and its contributors'' + * in the documentation or other materials provided with the distribution + * and in all advertising materials mentioning features or use of this + * software. Neither the name of the University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ +/* This is file MKTEMP.C */ +/* This file may have been modified by DJ Delorie (Jan 1991). If so, +** these modifications are Copyright (C) 1991 DJ Delorie. +*/ + +/* +FUNCTION +<>, <>, <>, <>, +<>---generate unused file name +<>---generate unused directory + +INDEX + mktemp +INDEX + mkdtemp +INDEX + mkstemp +INDEX + mkstemps +INDEX + mkostemp +INDEX + mkostemps +INDEX + _mktemp_r +INDEX + _mkdtemp_r +INDEX + _mkstemp_r +INDEX + _mkstemps_r +INDEX + _mkostemp_r +INDEX + _mkostemps_r + +ANSI_SYNOPSIS + #include + char *mktemp(char *<[path]>); + char *mkdtemp(char *<[path]>); + int mkstemp(char *<[path]>); + int mkstemps(char *<[path]>, int <[suffixlen]>); + int mkostemp(char *<[path]>, int <[flags]>); + int mkostemps(char *<[path]>, int <[suffixlen]>, int <[flags]>); + + char *_mktemp_r(struct _reent *<[reent]>, char *<[path]>); + char *_mkdtemp_r(struct _reent *<[reent]>, char *<[path]>); + int *_mkstemp_r(struct _reent *<[reent]>, char *<[path]>); + int *_mkstemps_r(struct _reent *<[reent]>, char *<[path]>, int <[len]>); + int *_mkostemp_r(struct _reent *<[reent]>, char *<[path]>, + int <[flags]>); + int *_mkostemps_r(struct _reent *<[reent]>, char *<[path]>, int <[len]>, + int <[flags]>); + +DESCRIPTION +<>, <>, and <> attempt to generate a file name +that is not yet in use for any existing file. <> and <> +create the file and open it for reading and writing; <> simply +generates the file name (making <> a security risk). <> +and <> allow the addition of other <> flags, such +as <>, <>, or <>. On platforms with a +separate text mode, <> forces <>, while <> +allows the choice between <>, <>, or 0 for default. +<> attempts to create a directory instead of a file, with a +permissions mask of 0700. + +You supply a simple pattern for the generated file name, as the string +at <[path]>. The pattern should be a valid filename (including path +information if you wish) ending with at least six `<>' +characters. The generated filename will match the leading part of the +name you supply, with the trailing `<>' characters replaced by some +combination of digits and letters. With <>, the `<>' +characters end <[suffixlen]> bytes before the end of the string. + +The alternate functions <<_mktemp_r>>, <<_mkdtemp_r>>, <<_mkstemp_r>>, +<<_mkostemp_r>>, <<_mkostemps_r>>, and <<_mkstemps_r>> are reentrant +versions. The extra argument <[reent]> is a pointer to a reentrancy +structure. + +RETURNS +<> returns the pointer <[path]> to the modified string +representing an unused filename, unless it could not generate one, or +the pattern you provided is not suitable for a filename; in that case, +it returns <>. Be aware that there is an inherent race between +generating the name and attempting to create a file by that name; +you are advised to use <>. + +<> returns the pointer <[path]> to the modified string if the +directory was created, otherwise it returns <>. + +<>, <>, <>, and <> return a file +descriptor to the newly created file, unless it could not generate an +unused filename, or the pattern you provided is not suitable for a +filename; in that case, it returns <<-1>>. + +NOTES +Never use <>. The generated filenames are easy to guess and +there's a race between the test if the file exists and the creation +of the file. In combination this makes <> prone to attacks +and using it is a security risk. Whenever possible use <> +instead. It doesn't suffer the race condition. + +PORTABILITY +ANSI C does not require either <> or <>; the System +V Interface Definition requires <> as of Issue 2. POSIX 2001 +requires <>, and POSIX 2008 requires <> while +deprecating <>. <>, <>, and <> +are not standardized. + +Supporting OS subroutines required: <>, <>, <>, <>. +*/ + +#include <_ansi.h> +#include +#include +#include +#include +#include +#include +#include +#include + +static int +_DEFUN(_gettemp, (ptr, path, doopen, domkdir, suffixlen, flags), + struct _reent *ptr _AND + char *path _AND + register int *doopen _AND + int domkdir _AND + size_t suffixlen _AND + int flags) +{ + register char *start, *trv; + char *end; +#ifdef __USE_INTERNAL_STAT64 + struct stat64 sbuf; +#else + struct stat sbuf; +#endif + unsigned int pid; + + pid = _getpid_r (ptr); + for (trv = path; *trv; ++trv) /* extra X's get set to 0's */ + continue; + if (trv - path < suffixlen) + { + ptr->_errno = EINVAL; + return 0; + } + trv -= suffixlen; + end = trv; + while (path < trv && *--trv == 'X') + { + *trv = (pid % 10) + '0'; + pid /= 10; + } + if (end - trv < 6) + { + ptr->_errno = EINVAL; + return 0; + } + + /* + * Check the target directory; if you have six X's and it + * doesn't exist this runs for a *very* long time. + */ + + for (start = trv + 1;; --trv) + { + if (trv <= path) + break; + if (*trv == '/') + { + *trv = '\0'; +#ifdef __USE_INTERNAL_STAT64 + if (_stat64_r (ptr, path, &sbuf)) +#else + if (_stat_r (ptr, path, &sbuf)) +#endif + return (0); + if (!(sbuf.st_mode & S_IFDIR)) + { + ptr->_errno = ENOTDIR; + return (0); + } + *trv = '/'; + break; + } + } + + for (;;) + { +#if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4 + if (domkdir) + { +#ifdef HAVE_MKDIR + if (_mkdir_r (ptr, path, 0700) == 0) + return 1; + if (ptr->_errno != EEXIST) + return 0; +#else /* !HAVE_MKDIR */ + ptr->_errno = ENOSYS; + return 0; +#endif /* !HAVE_MKDIR */ + } + else +#endif /* _ELIX_LEVEL */ + if (doopen) + { + if ((*doopen = _open_r (ptr, path, O_CREAT | O_EXCL | O_RDWR | flags, + 0600)) >= 0) + return 1; + if (ptr->_errno != EEXIST) + return 0; + } +#ifdef __USE_INTERNAL_STAT64 + else if (_stat64_r (ptr, path, &sbuf)) +#else + else if (_stat_r (ptr, path, &sbuf)) +#endif + return (ptr->_errno == ENOENT ? 1 : 0); + + /* tricky little algorithm for backward compatibility */ + for (trv = start;;) + { + if (trv == end) + return 0; + if (*trv == 'z') + *trv++ = 'a'; + else + { + /* Safe, since it only encounters 7-bit characters. */ + if (isdigit ((unsigned char) *trv)) + *trv = 'a'; + else + ++ * trv; + break; + } + } + } + /*NOTREACHED*/ +} + +#ifndef O_BINARY +# define O_BINARY 0 +#endif + +int +_DEFUN(_mkstemp_r, (ptr, path), + struct _reent *ptr _AND + char *path) +{ + int fd; + + return (_gettemp (ptr, path, &fd, 0, 0, O_BINARY) ? fd : -1); +} + +#if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4 +char * +_DEFUN(_mkdtemp_r, (ptr, path), + struct _reent *ptr _AND + char *path) +{ + return (_gettemp (ptr, path, (int *) NULL, 1, 0, 0) ? path : NULL); +} + +int +_DEFUN(_mkstemps_r, (ptr, path, len), + struct _reent *ptr _AND + char *path _AND + int len) +{ + int fd; + + return (_gettemp (ptr, path, &fd, 0, len, O_BINARY) ? fd : -1); +} + +int +_DEFUN(_mkostemp_r, (ptr, path, flags), + struct _reent *ptr _AND + char *path _AND + int flags) +{ + int fd; + + return (_gettemp (ptr, path, &fd, 0, 0, flags & ~O_ACCMODE) ? fd : -1); +} + +int +_DEFUN(_mkostemps_r, (ptr, path, len, flags), + struct _reent *ptr _AND + char *path _AND + int len _AND + int flags) +{ + int fd; + + return (_gettemp (ptr, path, &fd, 0, len, flags & ~O_ACCMODE) ? fd : -1); +} +#endif /* _ELIX_LEVEL */ + +char * +_DEFUN(_mktemp_r, (ptr, path), + struct _reent *ptr _AND + char *path) +{ + return (_gettemp (ptr, path, (int *) NULL, 0, 0, 0) ? path : (char *) NULL); +} + +#ifndef _REENT_ONLY + +int +_DEFUN(mkstemp, (path), + char *path) +{ + int fd; + + return (_gettemp (_REENT, path, &fd, 0, 0, O_BINARY) ? fd : -1); +} + +# if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 4 +char * +_DEFUN(mkdtemp, (path), + char *path) +{ + return (_gettemp (_REENT, path, (int *) NULL, 1, 0, 0) ? path : NULL); +} + +int +_DEFUN(mkstemps, (path, len), + char *path _AND + int len) +{ + int fd; + + return (_gettemp (_REENT, path, &fd, 0, len, O_BINARY) ? fd : -1); +} + +int +_DEFUN(mkostemp, (path, flags), + char *path _AND + int flags) +{ + int fd; + + return (_gettemp (_REENT, path, &fd, 0, 0, flags & ~O_ACCMODE) ? fd : -1); +} + +int +_DEFUN(mkostemps, (path, len, flags), + char *path _AND + int len _AND + int flags) +{ + int fd; + + return (_gettemp (_REENT, path, &fd, 0, len, flags & ~O_ACCMODE) ? fd : -1); +} +# endif /* _ELIX_LEVEL */ + +char * +_DEFUN(mktemp, (path), + char *path) +{ + return (_gettemp (_REENT, path, (int *) NULL, 0, 0, 0) ? path : (char *) NULL); +} + +#endif /* ! defined (_REENT_ONLY) */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/rename.c b/contrib/sdk/sources/newlib/libc/stdio/rename.c index 7bab82c31d..6eb1f7d19c 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/rename.c +++ b/contrib/sdk/sources/newlib/libc/stdio/rename.c @@ -1,70 +1,70 @@ -/* - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -/* -FUNCTION -<>---rename a file - -INDEX - rename - -ANSI_SYNOPSIS - #include - int rename(const char *<[old]>, const char *<[new]>); - -TRAD_SYNOPSIS - #include - int rename(<[old]>, <[new]>) - char *<[old]>; - char *<[new]>; - -DESCRIPTION -Use <> to establish a new name (the string at <[new]>) for a -file now known by the string at <[old]>. After a successful -<>, the file is no longer accessible by the string at <[old]>. - -If <> fails, the file named <<*<[old]>>> is unaffected. The -conditions for failure depend on the host operating system. - -RETURNS -The result is either <<0>> (when successful) or <<-1>> (when the file -could not be renamed). - -PORTABILITY -ANSI C requires <>, but only specifies that the result on -failure be nonzero. The effects of using the name of an existing file -as <<*<[new]>>> may vary from one implementation to another. - -Supporting OS subroutines required: <>, <>, or <>. -*/ - -#include <_ansi.h> -#include -#include -#include - -#ifndef _REENT_ONLY - -int -_DEFUN(rename, (old, new), - _CONST char *old _AND - _CONST char *new) -{ - return _rename_r (_REENT, old, new); -} - -#endif +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* +FUNCTION +<>---rename a file + +INDEX + rename + +ANSI_SYNOPSIS + #include + int rename(const char *<[old]>, const char *<[new]>); + +TRAD_SYNOPSIS + #include + int rename(<[old]>, <[new]>) + char *<[old]>; + char *<[new]>; + +DESCRIPTION +Use <> to establish a new name (the string at <[new]>) for a +file now known by the string at <[old]>. After a successful +<>, the file is no longer accessible by the string at <[old]>. + +If <> fails, the file named <<*<[old]>>> is unaffected. The +conditions for failure depend on the host operating system. + +RETURNS +The result is either <<0>> (when successful) or <<-1>> (when the file +could not be renamed). + +PORTABILITY +ANSI C requires <>, but only specifies that the result on +failure be nonzero. The effects of using the name of an existing file +as <<*<[new]>>> may vary from one implementation to another. + +Supporting OS subroutines required: <>, <>, or <>. +*/ + +#include <_ansi.h> +#include +#include +#include + +#ifndef _REENT_ONLY + +int +_DEFUN(rename, (old, new), + _CONST char *old _AND + _CONST char *new) +{ + return _rename_r (_REENT, old, new); +} + +#endif diff --git a/contrib/sdk/sources/newlib/libc/sys/_rename.c b/contrib/sdk/sources/newlib/libc/sys/_rename.c new file mode 100644 index 0000000000..56211d7370 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/_rename.c @@ -0,0 +1,71 @@ +/* _rename.c -- Implementation of the low-level rename() routine + * + * Copyright (c) 2004 National Semiconductor Corporation + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ + +#include +#include +#include +#include + +int _rename (char *from, char *to) +{ + void* buf; + int f_from; + int f_to; + int size; + + printf("%s from %s to %s\n", __FUNCTION__, + from, to); + + f_from = open(from,O_RDONLY); + + if (f_from < 0) + { + errno = ENOENT; + return -1; + }; + + f_to = open(to,O_CREAT|O_WRONLY|O_EXCL); + + if (f_to < 0) + { + close(f_from); + errno = EACCES; + return -1; + }; + + buf = alloca(32768); + + do + { + size = read(f_from, buf, 32768); + + if (size >= 0) + size = write(f_to, buf, size); + + }while (size == 32768); + + close(f_to); + close(f_from); + + if (size == -1) + { + errno = EACCES; + return -1; + }; + + remove(from); + + return (0); +}; diff --git a/contrib/sdk/sources/newlib/libc/sys/access.c b/contrib/sdk/sources/newlib/libc/sys/access.c new file mode 100644 index 0000000000..980682ef3b --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/access.c @@ -0,0 +1,33 @@ +/* This is file ACCESS.C */ +/* + * Copyright (C) 1993 DJ Delorie + * All rights reserved. + * + * Redistribution, modification, and use in source and binary forms is permitted + * provided that the above copyright notice and following paragraph are + * duplicated in all such forms. + * + * This file is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#include +#include + +int access(const char *fn, int flags) +{ + struct stat s; + if (stat(fn, &s)) + return -1; + if (s.st_mode & S_IFDIR) + return 0; + if (flags & W_OK) + { + if (s.st_mode & S_IWRITE) + return 0; + return -1; + } + return 0; +} + diff --git a/contrib/sdk/sources/newlib/libc/sys/create.c b/contrib/sdk/sources/newlib/libc/sys/create.c index b7d0149613..7a17279658 100644 --- a/contrib/sdk/sources/newlib/libc/sys/create.c +++ b/contrib/sdk/sources/newlib/libc/sys/create.c @@ -8,7 +8,7 @@ int create_file(const char *path) __asm__ __volatile__ ( "pushl $0 \n\t" "pushl $0 \n\t" - "movl %0, 1(%%esp) \n\t" + "movl %1, 1(%%esp) \n\t" "pushl $0 \n\t" "pushl $0 \n\t" "pushl $0 \n\t" diff --git a/contrib/sdk/sources/newlib/libc/sys/delete.c b/contrib/sdk/sources/newlib/libc/sys/delete.c deleted file mode 100644 index 92f18ff8bf..0000000000 --- a/contrib/sdk/sources/newlib/libc/sys/delete.c +++ /dev/null @@ -1,26 +0,0 @@ - -#include -#include - -int delete_file(const char *path) -{ - int retval; - __asm__ __volatile__ ( - "pushl $0 \n\t" - "pushl $0 \n\t" - "movl %0, 1(%%esp) \n\t" - "pushl $0 \n\t" - "pushl $0 \n\t" - "pushl $0 \n\t" - "pushl $0 \n\t" - "pushl $8 \n\t" - "movl %%esp, %%ebx \n\t" - "movl $70, %%eax \n\t" - "int $0x40 \n\t" - "addl $28, %%esp \n\t" - :"=a" (retval) - :"r" (path) - :"ebx"); - return retval; -}; - diff --git a/contrib/sdk/sources/newlib/libc/sys/fstat.c b/contrib/sdk/sources/newlib/libc/sys/fstat.c index 671376ab72..ecfbe73c3e 100644 --- a/contrib/sdk/sources/newlib/libc/sys/fstat.c +++ b/contrib/sdk/sources/newlib/libc/sys/fstat.c @@ -26,6 +26,8 @@ _DEFUN (fstat, (fd, buf), struct stat *buf) { fileinfo_t info; + struct tm time; + __io_handle *ioh; if( (fd < 0) || (fd >=64) ) @@ -47,9 +49,44 @@ _DEFUN (fstat, (fd, buf), ioh = &__io_tab[fd]; get_fileinfo(ioh->name, &info); - buf->st_mode = S_IFREG; + if (info.attr & 0x10) + buf->st_mode = S_IFDIR; + else + { + if (info.attr & 0x07) + buf->st_mode = S_IFREG|S_IRUSR|S_IXUSR; + else + buf->st_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IXUSR; + } buf->st_blksize = 4096; - buf->st_size = info.size; + + time.tm_sec = info.atime.sec; + time.tm_min = info.atime.min; + time.tm_hour = info.atime.hour; + time.tm_mday = info.adate.day; + time.tm_mon = info.adate.month; + time.tm_year = info.adate.year - 1900; + time.tm_isdst = -1; + buf->st_atime = mktime(&time); + + time.tm_sec = info.ctime.sec; + time.tm_min = info.ctime.min; + time.tm_hour = info.ctime.hour; + time.tm_mday = info.cdate.day; + time.tm_mon = info.cdate.month; + time.tm_year = info.cdate.year - 1900; + time.tm_isdst = -1; + buf->st_ctime = mktime(&time); + + time.tm_sec = info.mtime.sec; + time.tm_min = info.mtime.min; + time.tm_hour = info.mtime.hour; + time.tm_mday = info.mdate.day; + time.tm_mon = info.mdate.month; + time.tm_year = info.mdate.year - 1900; + time.tm_isdst = -1; + buf->st_mtime = mktime(&time); + }; return (0); diff --git a/contrib/sdk/sources/newlib/libc/sys/open.c b/contrib/sdk/sources/newlib/libc/sys/open.c index da990e40a3..8aa4ad58cf 100644 --- a/contrib/sdk/sources/newlib/libc/sys/open.c +++ b/contrib/sdk/sources/newlib/libc/sys/open.c @@ -128,8 +128,6 @@ int open (const char * filename, int flags, ...) buildpath(buf, filename); } -// printf("%s %s\n", __FUNCTION__, buf); - err = get_fileinfo(buf, &info); if( flags & O_EXCL && @@ -189,8 +187,6 @@ int open (const char * filename, int flags, ...) ioh->read = read_file; ioh->write = write_file; -// printf("%s %s\n", __FUNCTION__, ioh->name); - return hid; }; diff --git a/contrib/sdk/sources/newlib/libc/sys/stat.c b/contrib/sdk/sources/newlib/libc/sys/stat.c index ebb7de3f5f..a10d9b2107 100644 --- a/contrib/sdk/sources/newlib/libc/sys/stat.c +++ b/contrib/sdk/sources/newlib/libc/sys/stat.c @@ -13,7 +13,10 @@ * they apply. */ #include +#include #include +#include +#include #include "glue.h" /* @@ -24,7 +27,68 @@ _DEFUN (stat, (path, buf), const char *path _AND struct stat *buf) { - errno = EIO; - return (-1); + + fileinfo_t info; + struct tm time; + + if( get_fileinfo(path, &info)) + { + errno = ENOENT; + return (-1); + }; + + memset (buf, 0, sizeof (* buf)); + + buf->st_size = info.size; + + if (info.attr & 0x10) + buf->st_mode = S_IFDIR; + else + { + if (info.attr & 0x07) + buf->st_mode = S_IFREG|S_IRUSR|S_IXUSR; + else + buf->st_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IXUSR; + } + + buf->st_blksize = 4096; + + time.tm_sec = info.atime.sec; + time.tm_min = info.atime.min; + time.tm_hour = info.atime.hour; + time.tm_mday = info.adate.day; + time.tm_mon = info.adate.month; + time.tm_year = info.adate.year - 1900; + time.tm_isdst = -1; + buf->st_atime = mktime(&time); + + time.tm_sec = info.ctime.sec; + time.tm_min = info.ctime.min; + time.tm_hour = info.ctime.hour; + time.tm_mday = info.cdate.day; + time.tm_mon = info.cdate.month; + time.tm_year = info.cdate.year - 1900; + time.tm_isdst = -1; + buf->st_ctime = mktime(&time); + + time.tm_sec = info.mtime.sec; + time.tm_min = info.mtime.min; + time.tm_hour = info.mtime.hour; + time.tm_mday = info.mdate.day; + time.tm_mon = info.mdate.month; + time.tm_year = info.mdate.year - 1900; + time.tm_isdst = -1; + buf->st_mtime = mktime(&time); + + return (0); +} + + +int +_DEFUN (lstat, (path, buf), + const char *path _AND + struct stat *buf) +{ + return stat(path, buf); } diff --git a/contrib/sdk/sources/newlib/libc/sys/stat.c.bak b/contrib/sdk/sources/newlib/libc/sys/stat.c.bak new file mode 100644 index 0000000000..3cf162eb4d --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/stat.c.bak @@ -0,0 +1,96 @@ +/* stat.c -- Get the status of a file. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include +#include +#include "glue.h" + +/* + * stat -- Since we have no file system, we just return an error. + */ +int +_DEFUN (stat, (path, buf), + const char *path _AND + struct stat *buf) +{ + + fileinfo_t info; + struct tm time; + + printf("%s %s\n", __FUNCTION__, path); + + if( get_fileinfo(path, &info)) + { + errno = ENOENT; + return (-1); + }; + + memset (buf, 0, sizeof (* buf)); + + buf->st_size = info.size; + + if (info.attr & 0x10) + buf->st_mode = S_IFDIR; + else + { + if (info.attr & 0x07) + buf->st_mode = S_IFREG|S_IRUSR|S_IXUSR; + else + buf->st_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IXUSR; + } + + buf->st_blksize = 4096; + + time.tm_sec = info.atime.sec; + time.tm_min = info.atime.min; + time.tm_hour = info.atime.hour; + time.tm_mday = info.adate.day; + time.tm_mon = info.adate.month; + time.tm_year = info.adate.year - 1900; + time.tm_isdst = -1; + buf->st_atime = mktime(&time); + + time.tm_sec = info.ctime.sec; + time.tm_min = info.ctime.min; + time.tm_hour = info.ctime.hour; + time.tm_mday = info.cdate.day; + time.tm_mon = info.cdate.month; + time.tm_year = info.cdate.year - 1900; + time.tm_isdst = -1; + buf->st_ctime = mktime(&time); + + time.tm_sec = info.mtime.sec; + time.tm_min = info.mtime.min; + time.tm_hour = info.mtime.hour; + time.tm_mday = info.mdate.day; + time.tm_mon = info.mdate.month; + time.tm_year = info.mdate.year - 1900; + time.tm_isdst = -1; + buf->st_mtime = mktime(&time); + + return (0); +} + + +int +_DEFUN (lstat, (path, buf), + const char *path _AND + struct stat *buf) +{ + return stat(path, buf); +} + diff --git a/contrib/sdk/sources/newlib/libc/sys/unlink.c b/contrib/sdk/sources/newlib/libc/sys/unlink.c index 8e7a654ec7..eea265a30d 100644 --- a/contrib/sdk/sources/newlib/libc/sys/unlink.c +++ b/contrib/sdk/sources/newlib/libc/sys/unlink.c @@ -19,16 +19,48 @@ #include "glue.h" -/* - * unlink -- since we have no file system, - * we just return an error. - */ +static int delete_file(const char *path) +{ + int retval; + __asm__ __volatile__ ( + "pushl $0 \n\t" + "pushl $0 \n\t" + "movl %1, 1(%%esp) \n\t" + "pushl $0 \n\t" + "pushl $0 \n\t" + "pushl $0 \n\t" + "pushl $0 \n\t" + "pushl $8 \n\t" + "movl %%esp, %%ebx \n\t" + "movl $70, %%eax \n\t" + "int $0x40 \n\t" + "addl $28, %%esp \n\t" + :"=a" (retval) + :"r" (path) + :"ebx"); + return retval; +}; + + int _DEFUN (unlink, (path), char * path) { - errno = EIO; - return (-1); + int err; + + printf("%s %s\n", __FUNCTION__, path); + + err = delete_file(path); + + if (!err) + return 0; + + if (err == 5) + errno = ENOENT; + else + errno = EIO; + + return (-1); } int