Changeset 221afc9e in mainline


Ignore:
Timestamp:
2011-07-12T02:43:56Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2346e78
Parents:
46ac986
Message:

Redefinitions of some libc functions (mainly return value corrections).

Location:
uspace/lib/posix
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/fcntl.h

    r46ac986 r221afc9e  
    7171#define FD_CLOEXEC         1 /* Close on exec. */
    7272
     73#undef open
     74#define open(path, oflag, ...) \
     75        ({ \
     76                int rc = open(path, oflag, ##__VA_ARGS__); \
     77                if (rc < 0) { \
     78                        errno = -rc; \
     79                        rc = -1; \
     80                } \
     81                rc; \
     82        })
     83
    7384extern int posix_fcntl(int fd, int cmd, ...);
    7485
  • uspace/lib/posix/stdio.c

    r46ac986 r221afc9e  
    8686        s[0] = '\0';
    8787        return s;
     88}
     89
     90/**
     91 * Put a string on the stream.
     92 *
     93 * @param s String to be written.
     94 * @param stream Output stream.
     95 * @return Non-negative on success, EOF on failure.
     96 */
     97int posix_fputs(const char *restrict s, FILE *restrict stream)
     98{
     99        int rc = fputs(s, stream);
     100        if (rc == 0) {
     101                return EOF;
     102        } else {
     103                return 0;
     104        }
    88105}
    89106
     
    394411
    395412/**
     413 * Discard prefetched data or write unwritten data.
     414 *
     415 * @param stream Stream that shall be flushed.
     416 * @return Zero on success, EOF on failure.
     417 */
     418int posix_fflush(FILE *stream)
     419{
     420        int rc = fflush(stream);
     421        if (rc < 0) {
     422                errno = -rc;
     423                return EOF;
     424        } else {
     425                return 0;
     426        }
     427}
     428
     429/**
    396430 * Print formatted output to the opened file.
    397431 *
  • uspace/lib/posix/stdio.h

    r46ac986 r221afc9e  
    5353#undef putc
    5454#define putc fputc
     55extern int posix_fputs(const char *restrict s, FILE *restrict stream);
    5556#undef getc
    5657#define getc fgetc
     
    7980extern long posix_ftell(FILE *stream);
    8081extern posix_off_t posix_ftello(FILE *stream);
     82
     83/* Flushing Buffers */
     84extern int posix_fflush(FILE *stream);
    8185
    8286/* Formatted Output */
     
    122126        #define clearerr posix_clearerr
    123127
     128        #define fputs posix_fputs
    124129        #define ungetc posix_ungetc
    125130        #define getdelim posix_getdelim
     
    139144        #define ftell posix_ftell
    140145        #define ftello posix_ftello
     146
     147        #define fflush posix_fflush
    141148
    142149        #define dprintf posix_dprintf
  • uspace/lib/posix/unistd.c

    r46ac986 r221afc9e  
    9494
    9595/**
     96 * Get the pathname of the current working directory.
     97 *
     98 * @param buf Buffer into which the pathname shall be put.
     99 * @param size Size of the buffer.
     100 * @return Buffer pointer on success, NULL on failure.
     101 */
     102char *posix_getcwd(char *buf, size_t size)
     103{
     104        /* Native getcwd() does not set any errno despite the fact that general
     105         * usage pattern of this function depends on it (caller is repeatedly
     106         * guessing the required size of the buffer by checking for ERANGE on
     107         * failure). */
     108        if (size == 0) {
     109                errno = EINVAL;
     110                return NULL;
     111        }
     112        char *ret = getcwd(buf, size);
     113        if (ret == NULL && errno == EOK) {
     114                errno = ERANGE;
     115        }
     116        return ret;
     117}
     118
     119/**
    96120 * Determine the page size of the current run of the process.
    97121 *
     
    133157        /* There is currently no support for user accounts in HelenOS. */
    134158        return 0;
     159}
     160
     161/**
     162 * Read from a file.
     163 *
     164 * @param fildes File descriptor of the opened file.
     165 * @param buf Buffer to which the read bytes shall be stored.
     166 * @param nbyte Upper limit on the number of read bytes.
     167 * @return Number of read bytes on success, -1 otherwise.
     168 */
     169ssize_t posix_read(int fildes, void *buf, size_t nbyte)
     170{
     171        int rc = read(fildes, buf, nbyte);
     172        if (rc < 0) {
     173                errno = -rc;
     174                return -1;
     175        } else {
     176                return rc;
     177        }
     178}
     179
     180/**
     181 * Remove a link to a file.
     182 *
     183 * @param path File pathname.
     184 * @return Zero on success, -1 otherwise.
     185 */
     186int posix_unlink(const char *path)
     187{
     188        int rc = unlink(path);
     189        if (rc < 0) {
     190                errno = -rc;
     191                return -1;
     192        } else {
     193                return rc;
     194        }
    135195}
    136196
  • uspace/lib/posix/unistd.h

    r46ac986 r221afc9e  
    5151extern char **posix_environ;
    5252
     53/* Login Information */
    5354extern char *posix_getlogin(void);
    5455extern int posix_getlogin_r(char *name, size_t namesize);
     
    5657/* Identifying Terminals */
    5758extern int posix_isatty(int fd);
     59
     60/* Working Directory */
     61extern char *posix_getcwd(char *buf, size_t size);
    5862
    5963/* Query Memory Parameters */
     
    6468extern posix_uid_t posix_getuid(void);
    6569extern posix_gid_t posix_getgid(void);
     70
     71/* File Input/Output */
     72extern ssize_t posix_read(int fildes, void *buf, size_t nbyte);
     73
     74/* Deleting Files */
     75extern int posix_unlink(const char *path);
    6676
    6777/* Standard Streams */
     
    129139#ifndef LIBPOSIX_INTERNAL
    130140        #define environ posix_environ
     141
    131142        #define getlogin posix_getlogin
    132143        #define getlogin_r posix_getlogin_r
     144
     145        #define getcwd posix_getcwd
    133146
    134147        #define isatty posix_isatty
     
    140153        #define getuid posix_getuid
    141154        #define getgid posix_getgid
     155
     156        #define read posix_read
     157
     158        #define unlink posix_unlink
    142159
    143160        #define access posix_access
Note: See TracChangeset for help on using the changeset viewer.