diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2001-07-27 07:10:07 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2001-07-27 07:10:07 +0000 |
commit | a92afea5e51681dc36b6518d9539e32ea6713eeb (patch) | |
tree | 788e781060cfe3b3e100a3c61876943727f0408e /test | |
parent | 4c000249c5e1db827748791bbc08b75d0f2bc2b9 (diff) | |
download | libapr-a92afea5e51681dc36b6518d9539e32ea6713eeb.tar.gz |
Fixes and goodness
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62042 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/testmmap.c | 6 | ||||
-rw-r--r-- | test/testuser.c | 63 |
2 files changed, 41 insertions, 28 deletions
diff --git a/test/testmmap.c b/test/testmmap.c index eaf53e89a..0fe59b90e 100644 --- a/test/testmmap.c +++ b/test/testmmap.c @@ -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 @@ int main(void) } 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); diff --git a/test/testuser.c b/test/testuser.c index 4de8ff9ed..9c7b3e43a 100644 --- a/test/testuser.c +++ b/test/testuser.c @@ -72,20 +72,12 @@ int main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) 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); + 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_userid(&userid, &groupid, username, p); + 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; } |