OSDN Git Service

libc: Avoid redundant setting of ENOMEM
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Mon, 19 Jan 2015 21:49:10 +0000 (22:49 +0100)
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Thu, 22 Jan 2015 10:39:24 +0000 (11:39 +0100)
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
libc/misc/dirent/opendir.c
libc/stdlib/_atexit.c
libc/stdlib/malloc-simple/alloc.c
libc/stdlib/malloc-standard/malloc.c
libc/stdlib/malloc-standard/malloc.h
libc/stdlib/setenv.c
libc/stdlib/unix_grantpt.c
libc/string/_collate.c

index 66a5cc9..8af00f8 100644 (file)
@@ -110,7 +110,7 @@ DIR *opendir(const char *name)
 
        if (!ptr) {
                close_not_cancel_no_status(fd);
-               __set_errno(ENOMEM);
+               /* __set_errno(ENOMEM); */
        }
        return ptr;
 }
index ef6772f..3faa9f0 100644 (file)
@@ -257,7 +257,7 @@ struct exit_function attribute_hidden *__new_exitfn(void)
         efp = realloc(__exit_function_table,
                     (__exit_slots+20)*sizeof(struct exit_function));
         if (efp == NULL) {
-            __set_errno(ENOMEM);
+            /* __set_errno(ENOMEM); */
            goto DONE;
         }
         __exit_function_table = efp;
index 14f3846..a3c068a 100644 (file)
@@ -42,8 +42,10 @@ void *malloc(size_t size)
 
        result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE,
                      MMAP_FLAGS, 0, 0);
-       if (result == MAP_FAILED)
+       if (result == MAP_FAILED) {
+               __set_errno(ENOMEM);
                return 0;
+       }
        * (size_t *) result = size;
        return(result + sizeof(size_t));
 }
index 3253ebd..2abb5bb 100644 (file)
@@ -744,7 +744,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
     }
 
     /* catch all failure paths */
-    errno = ENOMEM;
+    __set_errno(ENOMEM);
     return 0;
 }
 
index d945627..1a4cc5a 100644 (file)
@@ -512,7 +512,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
 #define checked_request2size(req, sz)                             \
   if (REQUEST_OUT_OF_RANGE(req)) {                                \
-    errno = ENOMEM;                                               \
+    __set_errno(ENOMEM);                                          \
     return 0;                                                     \
   }                                                               \
   (sz) = request2size(req);
index 00e3f3d..f3b53b6 100644 (file)
@@ -76,7 +76,7 @@ static int __add_to_environ(const char *name, const char *value,
        /* We allocated this space; we can extend it.  */
        new_environ = realloc(last_environ, (size + 2) * sizeof(char *));
        if (new_environ == NULL) {
-               __set_errno(ENOMEM);
+               /* __set_errno(ENOMEM); */
                goto DONE;
        }
        if (__environ != last_environ) {
@@ -97,7 +97,7 @@ static int __add_to_environ(const char *name, const char *value,
 
                var_val = malloc(namelen + 1 + vallen);
                if (var_val == NULL) {
-                       __set_errno(ENOMEM);
+                       /* __set_errno(ENOMEM); */
                        goto DONE;
                }
                memcpy(var_val, name, namelen);
index 5dbb7f5..66c18c0 100644 (file)
@@ -68,7 +68,7 @@ pts_name (int fd, char **pts, size_t buf_len)
       if (! new_buf)
        {
          rv = -1;
-         errno = ENOMEM;
+         /* __set_errno(ENOMEM); */
          break;
        }
       buf = new_buf;
index 2ebfb93..93501b8 100644 (file)
@@ -367,7 +367,7 @@ static void next_weight(col_state_t *cs, int pass   __LOCALE_PARAM )
                                                if (cs->back_buf == cs->ibb) { /* was using internal buffer */
                                                        cs->bp = malloc(cs->bb_size + 128);
                                                        if (!cs->bp) {
-                                                               __set_errno(ENOMEM);
+                                                               /* __set_errno(ENOMEM); */
 #ifdef __UCLIBC_MJN3_ONLY__
 #warning what to do here?
 #endif
@@ -379,7 +379,7 @@ static void next_weight(col_state_t *cs, int pass   __LOCALE_PARAM )
                                                } else {
                                                        cs->bp = realloc(cs->back_buf, cs->bb_size + 128);
                                                        if (!cs->bp) {
-                                                               __set_errno(ENOMEM);
+                                                               /* __set_errno(ENOMEM); */
 #ifdef __UCLIBC_MJN3_ONLY__
 #warning what to do here?
 #endif