2 * user.c: APR wrapper functions for Subversion
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
20 #include <apr_pools.h>
27 /* Get the current user's name from the OS */
29 get_os_username(apr_pool_t
*pool
)
36 if (apr_uid_current(&uid
, &gid
, pool
) == APR_SUCCESS
&&
37 apr_uid_name_get(&username
, uid
, pool
) == APR_SUCCESS
)
44 /* Return a UTF8 version of STR, or NULL on error.
45 Use POOL for any necessary allocation. */
47 utf8_or_nothing(const char *str
, apr_pool_t
*pool
) {
51 svn_error_t
*err
= svn_utf_cstring_to_utf8(&utf8_str
, str
, pool
);
60 svn_user_get_name(apr_pool_t
*pool
)
62 const char *username
= get_os_username(pool
);
63 return utf8_or_nothing(username
, pool
);
67 svn_user_get_homedir(apr_pool_t
*pool
)
72 if (apr_env_get(&homedir
, "HOME", pool
) == APR_SUCCESS
)
73 return utf8_or_nothing(homedir
, pool
);
75 username
= get_os_username(pool
);
76 if (username
!= NULL
&&
77 apr_uid_homepath_get(&homedir
, username
, pool
) == APR_SUCCESS
)
78 return utf8_or_nothing(homedir
, pool
);