5
Last change
on this file since 1c6926c1 was
a2e3f33,
checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 11:50:54
|
score: Create object implementation header
Move implementation specific parts of object.h and object.inl into new
header file objectimpl.h. The object.h contains now only the
application visible API.
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Get User Name |
---|
5 | * @ingroup libcsupport |
---|
6 | */ |
---|
7 | |
---|
8 | #if HAVE_CONFIG_H |
---|
9 | #include "config.h" |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <limits.h> |
---|
13 | #include <string.h> |
---|
14 | #include <sys/types.h> |
---|
15 | #include <errno.h> |
---|
16 | |
---|
17 | #include <rtems/system.h> |
---|
18 | #include <rtems/seterr.h> |
---|
19 | #include <rtems/userenv.h> |
---|
20 | |
---|
21 | #include <unistd.h> |
---|
22 | #include <pwd.h> |
---|
23 | |
---|
24 | /** |
---|
25 | * 4.2.4 Get User Name, P1003.1b-1993, p. 87 |
---|
26 | * |
---|
27 | * @note P1003.1c/D10, p. 49 adds getlogin_r(). |
---|
28 | */ |
---|
29 | char *getlogin( void ) |
---|
30 | { |
---|
31 | (void) getlogin_r( _POSIX_types_Getlogin_buffer, LOGIN_NAME_MAX ); |
---|
32 | return _POSIX_types_Getlogin_buffer; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * 4.2.4 Get User Name, P1003.1b-1993, p. 87 |
---|
37 | * |
---|
38 | * @note P1003.1c/D10, p. 49 adds getlogin_r(). |
---|
39 | */ |
---|
40 | int getlogin_r( |
---|
41 | char *name, |
---|
42 | size_t namesize |
---|
43 | ) |
---|
44 | { |
---|
45 | struct passwd *pw; |
---|
46 | char *pname; |
---|
47 | |
---|
48 | if ( !name ) |
---|
49 | return EFAULT; |
---|
50 | |
---|
51 | if ( namesize < LOGIN_NAME_MAX ) |
---|
52 | return ERANGE; |
---|
53 | |
---|
54 | /* Set the pointer to a default name */ |
---|
55 | pname = ""; |
---|
56 | |
---|
57 | pw = getpwuid(getuid()); |
---|
58 | if ( pw ) |
---|
59 | pname = pw->pw_name; |
---|
60 | |
---|
61 | strncpy( name, pname, LOGIN_NAME_MAX ); |
---|
62 | return 0; |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.