014
29.09.2006, 16:29 Uhr
FloSoft
Medialer Over-Flow (Administrator)
|
getlogin/_r benutzt einen syscall um den namen abzufragen - woher der syscall dann die daten hat macht der kernel:
C++: |
/* Cache the system call's return value. */ char *__getlogin_cache; /* The kernel never returns more than MAXLOGNAME bytes, therefore we don't need more than that either. */ char __getlogin_cache_room[MAXLOGNAME];
extern int __syscall_getlogin (char *__name, size_t __name_len);
/* Return at most NAME_LEN characters of the login name of the user in NAME. If it cannot be determined or some other error occurred, return the error code. Otherwise return 0. Note that the getlogin_r function in FreeBSD libc returns a 'char *', but SUSV2 wants a return type of 'int'. */
int getlogin_r (char *name, size_t name_len) { size_t len;
if (__getlogin_cache == NULL) { if (INLINE_SYSCALL (getlogin, 2, __getlogin_cache_room, MAXLOGNAME) < 0) return -1; /* The system call should return a NULL terminated name. */ if (__memchr (__getlogin_cache_room, '\0', MAXLOGNAME) == NULL) abort (); __getlogin_cache = __getlogin_cache_room; }
len = strlen (__getlogin_cache); if (__builtin_expect (len < name_len, 1)) { memcpy (name, __getlogin_cache, len + 1); return 0; } else { __set_errno (ERANGE); return -1; } }
|
-- class God : public ChuckNorris { }; |