Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ec18957a in mainline


Ignore:
Timestamp:
2011-07-08T00:54:24Z (10 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master
Children:
9c1984f
Parents:
3f466c33
Message:

Added errno.h (see commentary inside).

Location:
uspace/lib/posix
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/Makefile

    r3f466c33 rec18957a  
    4040SOURCES = \
    4141        ctype.c \
     42        errno.c \
    4243        fcntl.c \
    4344        fnmatch.c \
  • uspace/lib/posix/fcntl.c

    r3f466c33 rec18957a  
    3737#include "internal/common.h"
    3838#include "fcntl.h"
     39
    3940#include "libc/unistd.h"
    4041#include "libc/vfs/vfs.h"
    41 #include <errno.h>
     42#include "errno.h"
    4243
    4344/**
     
    6566                rc = fd_node(fd, &node);
    6667                if (rc != EOK) {
    67                         // TODO: propagate a POSIX compatible errno
     68                        errno = -rc;
    6869                        return -1;
    6970                }
     
    7273                int newfd = open_node(&node, 0);
    7374                if (newfd < 0) {
    74                         // TODO: propagate a POSIX compatible errno
     75                        errno = -newfd;
    7576                        return -1;
    7677                }
     
    8182                rc = dup2(fd, newfd);
    8283                if (rc != EOK) {
    83                         // TODO: propagate a POSIX compatible errno
     84                        errno = -rc;
    8485                        return -1;
    8586                }
  • uspace/lib/posix/stdio/scanf.c

    r3f466c33 rec18957a  
    3939
    4040#include "../assert.h"
    41 #include <errno.h>  // FIXME: use POSIX errno
     41#include "../errno.h"
    4242
    4343#include "../stdio.h"
  • uspace/lib/posix/stdlib.c

    r3f466c33 rec18957a  
    3939#include "stdlib.h"
    4040
     41#include "errno.h"
     42
    4143#include "libc/sort.h"
    4244#include "libc/str.h"
    4345#include "libc/vfs/vfs.h"
    44 #include <errno.h>  // FIXME: use POSIX errno
    4546
    4647/**
  • uspace/lib/posix/stdlib/strtol.c

    r3f466c33 rec18957a  
    4040#include "../limits.h"
    4141#include "../ctype.h"
    42 #include <errno.h> // FIXME: use POSIX errno
     42#include "../errno.h"
    4343
    4444// TODO: documentation
  • uspace/lib/posix/stdlib/strtold.c

    r3f466c33 rec18957a  
    3535#define LIBPOSIX_INTERNAL
    3636
    37 /* Has to be first. */
     37/* Must be first. */
    3838#include "../stdbool.h"
    3939
     
    4545#include "../stdint.h"
    4646#include "../strings.h"
    47 #include <errno.h> // FIXME: use POSIX errno
     47#include "../errno.h"
    4848
    4949#ifndef HUGE_VALL
  • uspace/lib/posix/string.c

    r3f466c33 rec18957a  
    510510char *posix_strerror(int errnum)
    511511{
    512         /* uses function from libc, we just have to negate errno
    513          * (POSIX uses positive errorcodes, HelenOS has negative)
     512        /* Uses function from libc, we just have to negate errno
     513         * (POSIX uses positive errorcodes, HelenOS has negative).
    514514         */
    515         return (char *) str_error(-errnum);
     515        // FIXME: not all POSIX error codes are in libc
     516        return (char *) str_error(-posix_abs(errnum));
    516517}
    517518
  • uspace/lib/posix/sys/stat.c

    r3f466c33 rec18957a  
    3939#include "stat.h"
    4040
     41#include "../errno.h"
    4142#include "../libc/mem.h"
    4243
     
    7677{
    7778        struct stat hst;
    78         if (fstat(fd, &hst) == -1) {
    79                 // TODO: propagate a POSIX compatible errno
     79        int rc = fstat(fd, &hst);
     80        if (rc < 0) {
     81                /* fstat() returns negative error code instead of using errno.
     82                 */
     83                errno = -rc;
    8084                return -1;
    8185        }
     
    107111{
    108112        struct stat hst;
    109         if (stat(path, &hst) == -1) {
    110                 // TODO: propagate a POSIX compatible errno
     113        int rc = stat(path, &hst);
     114        if (rc < 0) {
     115                /* stat() returns negative error code instead of using errno.
     116                 */
     117                errno = -rc;
    111118                return -1;
    112119        }
  • uspace/lib/posix/unistd.c

    r3f466c33 rec18957a  
    3838#include "internal/common.h"
    3939#include "unistd.h"
    40 #include <task.h>
    41 #include <errno.h>
     40
     41#include "errno.h"
    4242#include "string.h"
    4343#include "fcntl.h"
    44 #include <stats.h>
     44
     45#include "libc/task.h"
     46#include "libc/stats.h"
    4547#include "libc/malloc.h"
    4648
     
    145147                /* Check file existence by attempt to open it. */
    146148                int fd = open(path, O_RDONLY);
    147                 // TODO: propagate a POSIX compatible errno
    148                 int rc = fd < 0 ? -1 : 0;
    149                 close(fd);
    150                 return rc;
     149                if (fd < 0) {
     150                        /* FIXME: open() returns error code as negative retval. */
     151                        errno = -fd;
     152                        fd = -1;
     153                } else {
     154                        close(fd);
     155                }
     156                return fd;
    151157        } else if (amode & (X_OK | W_OK | R_OK)) {
    152158                /* HelenOS doesn't support permissions, return success. */
Note: See TracChangeset for help on using the changeset viewer.