Unix, C, and C++
Function Reference
General Unix
void exit(int status)
include: <stdlib.h>
Terminates the current program or process.
First, all atexit functions are called,
then all open files or streams are flushed (unwritten data is written),
then all open files or streams are closed,
then the process is terminated.
The value 'status' indicates the exit status, 0=OK, other=not OK.
void atexit(function)
include: <stdlib.h>
function = any function with type void f(void)
returns <0 for error, 0 if successful.
Registers the function for automatic calling on exit. Registered
functions are all automatically called in reverse order when the
program terminates (whether or not exit() is the
cause of termination. The number of atexit functions may be limited,
but at least 32 must be allowed.
char * getcwd(char * s, int len)
include: <unistd.h>
Stores the current working directory (pwd) in the string s. If the length
of that string would be greater than len-1 characters, it is truncated.
The string s is also returned as the result of this function.
The maximum possible length of a pathname is defined in <sys/param.h> with
the name MAXPATHLEN.
Example:
char path[MAXPATHLEN];
getcwd(path, MAXPATHLEN);
printf("pwd -> %s\n", path);
int getuid(void)
include: <unistd.h>
Returns the 'real' User Identification Number (uid) associated with the current
process. There is a unique UID assigned to every individual user on a properly
set-up system.
The word 'real' is only significant for SUID programs. When a program has its
SetUID bit set, it behaves as though it were owned by a different user. The
'real' UID is the UID of the process that started this program; the 'effective'
UID is the UID that the program is actually running under. It is the effective
UID that determines what a program can do, and the real UID that identifies who
is really responsible for it.
Root has a UID of zero, all other users are non-zero.
int geteuid(void)
include: <unistd.h>
Returns the 'effective' User Identification Number (uid) associated with the current
process. There is a unique UID assigned to every individual user on a properly
set-up system.
The word 'effective' is only significant for SUID programs. When a program has its
SetUID bit set, it behaves as though it were owned by a different user. The
'real' UID is the UID of the process that started this program; the 'effective'
UID is the UID that the program is actually running under. It is the effective
UID that determines what a program can do, and the real UID that identifies who
is really responsible for it.
Root has a UID of zero, all other users are non-zero.
int setuid(int uid)
include: <unistd.h>
Changes both the real and effective UID of the current process.
This function will fail unless the current effective UID is 0 (root) or the parameter
is equal to the current real or effective UID.
Returns 0 if successful, negative if not.
int seteuid(int uid)
include: <unistd.h>
Changes the effective UID of the current process.
The effective UID may only be set to the real UID or the previous value of the
effective UID that was changed by an earlier setuid or seteuid.
Returns 0 if successful, negative if not.
See also:
void perror(char * message): print error message
char * strerror(int errnum): retrieve error message