apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/test testmmap.c testuser.c
Date Fri, 27 Jul 2001 07:10:07 GMT
wrowe       01/07/27 00:10:07

  Modified:    test     testmmap.c testuser.c
  Log:
    Fixes and goodness
  
  Revision  Changes    Path
  1.28      +3 -3      apr/test/testmmap.c
  
  Index: testmmap.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testmmap.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- testmmap.c	2001/06/08 04:49:48	1.27
  +++ testmmap.c	2001/07/27 07:10:07	1.28
  @@ -57,6 +57,7 @@
   #include "apr_general.h"
   #include "apr_lib.h"
   #include "apr_file_io.h"
  +#include "apr_strings.h"
   #if APR_HAVE_UNISTD_H
   #include <unistd.h>
   #endif
  @@ -98,9 +99,8 @@
       }
       fprintf(stdout,"OK\n");
       
  -    file1 = (char*) apr_palloc(context, sizeof(char) * PATH_LEN);
  -    getcwd(file1, PATH_LEN);
  -    strncat(file1,"/testmmap.c",11);  
  +    apr_filepath_get(&file1, context);
  +    file1 = apr_pstrcat(context,file1,"/testmmap.c",NULL);
   
       fprintf(stdout, "Opening file........................");
       rv = apr_file_open(&thefile, file1, flag, APR_UREAD | APR_GREAD, context);
  
  
  
  1.2       +39 -26    apr/test/testuser.c
  
  Index: testuser.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testuser.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testuser.c	2001/07/20 13:28:43	1.1
  +++ testuser.c	2001/07/27 07:10:07	1.2
  @@ -72,20 +72,12 @@
       apr_pool_t *p;
       apr_status_t rv;
       char msgbuf[80];
  -    const char *username;
  +    char *groupname;
  +    char *username;
       char *homedir;
       apr_uid_t userid;
       apr_gid_t groupid;
   
  -    if (argc != 2) {
  -        fprintf(stderr,
  -                "usage: %s username\n",
  -                argv[0]);
  -        exit(-1);
  -    }
  -
  -    username = argv[1];
  -
       if (apr_initialize() != APR_SUCCESS) {
           fprintf(stderr, "Something went wrong\n");
           exit(-1);
  @@ -97,30 +89,51 @@
           exit(-1);
       }
   
  -    rv = apr_get_home_directory(&homedir, username, p);
  -    if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_get_home_directory(,%s,) failed: %s\n",
  -                username,
  -                apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  -        exit(-1);
  +    if (argc != 2) {
  +        fprintf(stderr,
  +                "optional: %s username\n",
  +                argv[0]);
  +        if ((rv = apr_current_userid(&userid, &groupid, p)) != APR_SUCCESS) {
  +            fprintf(stderr, "apr_current_userid failed: %s\n",
  +                    apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  +            exit(-1);
  +        }
  +        apr_get_username(&username, userid, p);
  +        if (rv != APR_SUCCESS) {
  +            fprintf(stderr, "apr_get_username(,,) failed: %s\n",
  +                    apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  +            exit(-1);
  +        }
       }
       else {
  -        printf("home directory for %s: `%s'\n",
  -               username, homedir);
  -    }
  +        username = argv[1];
   
  -    rv = apr_get_userid(&userid, &groupid, username, p);
  +        rv = apr_get_userid(&userid, &groupid, username, p);
  +        if (rv != APR_SUCCESS) {
  +            fprintf(stderr, "apr_get_userid(,,%s,) failed: %s\n",
  +                    username,
  +                    apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  +            exit(-1);
  +        }
  +    }
  +
  +    rv = apr_get_groupname(&groupname, groupid, p);
  +    if (rv != APR_SUCCESS)
  +        groupname = "(none)";
  +
  +    printf("user/group ids for %s: %d/%d\n",
  +           username,
  +           (int)userid, (int)groupid);
  +
  +    rv = apr_get_home_directory(&homedir, username, p);
       if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_get_userid(,,%s,) failed: %s\n",
  +        fprintf(stderr, "apr_get_home_directory(,%s,) failed: %s\n",
                   username,
                   apr_strerror(rv, msgbuf, sizeof(msgbuf)));
           exit(-1);
  -    }
  -    else {
  -        printf("user/group ids for %s: %d/%d\n",
  -               username,
  -               (int)userid, (int)groupid);
       }
  +    printf("home directory for %s (member of %s) is:\n`%s'\n",
  +           username, groupname, homedir);
   
       return 1;
   }
  
  
  

Mime
View raw message