full file. should work fine.
This commit is contained in:
parent
bfb3a7da94
commit
69f93af25b
1 changed files with 21 additions and 0 deletions
21
logname.c
Normal file
21
logname.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue