getpwnam_error.c
changeset 33 5e0a954f7c0b
child 59 a7ba10b68915
equal deleted inserted replaced
32:9b56360ec64e 33:5e0a954f7c0b
       
     1 /**
       
     2  * test/demos/getpwnam_error.c
       
     3  * Copyright (C) 2008 Markus Broeker
       
     4  */
       
     5 
       
     6 #include <stdio.h>
       
     7 #include <stdlib.h>
       
     8 
       
     9 #include <pwd.h>
       
    10 
       
    11 /**
       
    12 ==7531==
       
    13 ==7531== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 25 from 2)
       
    14 ==7531== malloc/free: in use at exit: 156 bytes in 11 blocks.
       
    15 ==7531== malloc/free: 66 allocs, 55 frees, 6,342 bytes allocated.
       
    16 ==7531== For counts of detected errors, rerun with: -v
       
    17 ==7531== searching for pointers to 11 not-freed blocks.
       
    18 ==7531== checked 60,444 bytes.
       
    19 ==7531==
       
    20 ==7531== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 1 of 3
       
    21 ==7531==    at 0x4022D6E: malloc (vg_replace_malloc.c:207)
       
    22 ==7531==    by 0x412C7E0: (within /lib/i686/cmov/libc-2.7.so)
       
    23 ==7531==    by 0x412D0DB: __nss_database_lookup (in /lib/i686/cmov/libc-2.7.so)
       
    24 ==7531==    by 0x4596F5B: ???
       
    25 ==7531==    by 0x4597CF6: ???
       
    26 ==7531==    by 0x40D3BD1: getpwnam_r (in /lib/i686/cmov/libc-2.7.so)
       
    27 ==7531==    by 0x40D3646: getpwnam (in /lib/i686/cmov/libc-2.7.so)
       
    28 ==7531==    by 0x8048478: main (getpwnam_error.c:48)
       
    29 ==7531==
       
    30 ==7531== LEAK SUMMARY:
       
    31 ==7531==    definitely lost: 36 bytes in 1 blocks.
       
    32 ==7531==    indirectly lost: 120 bytes in 10 blocks.
       
    33 ==7531==      possibly lost: 0 bytes in 0 blocks.
       
    34 ==7531==    still reachable: 0 bytes in 0 blocks.
       
    35 ==7531==         suppressed: 0 bytes in 0 blocks.
       
    36 */
       
    37 
       
    38 int main (int argc, char **argv)
       
    39 {
       
    40     struct passwd *pwd;
       
    41     char *user;
       
    42 
       
    43     if ((user = getenv ("USER")) == NULL) {
       
    44         printf ("This system isn't supported yet\n");
       
    45         return EXIT_FAILURE;
       
    46     }
       
    47 
       
    48     if ((pwd = getpwnam (user)) == NULL) {
       
    49         printf ("I wasn't able to retrieve the neccessary data\n");
       
    50         return EXIT_FAILURE;
       
    51     }
       
    52 
       
    53     printf ("Your full name: %s\n", pwd->pw_gecos);
       
    54 
       
    55     return EXIT_SUCCESS;
       
    56 }