FENIX_coreutils/logname.c

23 lines
540 B
C
Raw Normal View History

#define _POSIX_C_SOURCE 200809L
2020-12-11 07:20:00 +00:00
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char * argv[]) {
char * logname = getlogin();
if(logname == NULL) {
switch(errno) {
case EMFILE: fprintf(stderr, "%s: all file descriptors open\n", argv[0]);
break;
case ENFILE: fprintf(stderr, "%s: too many files open", argv[0]); break;
default: fprintf(stderr, "%s: other/unknown error", argv[0]);
}
return 1;
}
else {
printf("%s\n", logname);
return 0;
}
}