#include "apue.h"
#include <stdio.h>
#include <fcntl.h>

int main(int argc, char* argv[]) {
int val;

if (argc != 2)
err_quit("error quit.");

if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0)
err_sys("fcntl error for id: %d", atoi(argv[1]));

switch(val & O_ACCMODE) {
case O_RDONLY:
printf("read only.\n");
break;
case O_WRONLY:
printf("write only.\n");
break;
case O_RDWR:
printf("read write.\n");
default:
err_dump("unknow access mode.");
}

if (val & O_APPEND) {
printf(", append\n");
}

if (val & O_NONBLOCK) {
printf(", non block\n");
}

if (val & O_SYNC) {
printf(", synchronours writes \n");
}

#if !defined(_POXIX_C_SOURCE) && defined(O_FSYNC) && (O_FSYNC != O_SYNC)
if (val & O_SYNC) {
printf(", synchronours writes\n");
}
#endif

putchar('\n');

exit(0);
}