diff --git a/2/limits/.isoc.c.swp b/2/limits/.isoc.c.swp new file mode 100644 index 0000000..8c9c729 Binary files /dev/null and b/2/limits/.isoc.c.swp differ diff --git a/2/limits/conf.c b/2/limits/conf.c new file mode 100644 index 0000000..b526e5e --- /dev/null +++ b/2/limits/conf.c @@ -0,0 +1,39 @@ +#include +#include +#include + +extern int errno; + +static long posix_version = 0; + +static long xsi_version = 0; + +int main(void) { + + // get interface version + posix_version = sysconf(_SC_VERSION); + xsi_version = sysconf(_SC_XOPEN_VERSION); + + printf("%ld %ld\n", posix_version, xsi_version); + + // sysconf + printf("%ld\n", sysconf(_SC_ARG_MAX)); + printf("%ld %ld\n", sysconf(_SC_CHILD_MAX), sysconf(_SC_CLK_TCK)); + printf("%ld %ld\n", sysconf(_SC_LOGIN_NAME_MAX), sysconf(_SC_OPEN_MAX)); + printf("%ld\n", sysconf(_SC_SEM_NSEMS_MAX)); + + if(!~sysconf(_SC_SEM_NSEMS_MAX) && errno == EINVAL){ + printf("Not a proper value.\n"); + } + + printf("%ld %ld\n", sysconf(_SC_TIMER_MAX), sysconf(_SC_STREAM_MAX)); + + // pathconf + printf("%ld\n", pathconf("./conf.c", _PC_FILESIZEBITS)); + printf("%ld\n", pathconf("./conf.c", _PC_NAME_MAX)); + // printf("%ld\n", pathconf("./conf.c", _PC_TIMESTAMP_RESOLUTION)); + printf("%ld\n", pathconf("./conf.c", _PC_PATH_MAX)); + printf("%ld\n", pathconf("./conf.c", _PC_LINK_MAX)); + + return 0; +} diff --git a/2/limits/isoc.c b/2/limits/isoc.c index e7b4062..77305d1 100644 --- a/2/limits/isoc.c +++ b/2/limits/isoc.c @@ -2,12 +2,22 @@ #include int main(void){ + // char printf("%d %d %d\n", CHAR_BIT, CHAR_MAX, CHAR_MIN); + // signed char + printf("%d %d\n", SCHAR_MAX, SCHAR_MIN); + // unsigned char + printf("%d\n", UCHAR_MAX); + // int printf("%d %d\n", INT_MAX, INT_MIN); + // short printf("%d %d\n", SHRT_MAX, SHRT_MIN); + // long printf("%ld %ld\n", LONG_MAX, LONG_MIN); + // long long printf("%lld %lld\n", LLONG_MAX, LLONG_MIN); - + // extra printf("%d %d %d\n", FOPEN_MAX, TMP_MAX, FILENAME_MAX); + return 0; } diff --git a/2/limits/openmax.c b/2/limits/openmax.c new file mode 100644 index 0000000..9a37a49 --- /dev/null +++ b/2/limits/openmax.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +#ifdef OPEN_MAX +static long openmax = OPEN_MAX; +#else +static long openmax = 0; +#endif + +#define OPEN_MAX_GUESS 256 + +int main(void){ + + if(openmax == 0) { + errno = 0; + if((openmax = sysconf(_SC_OPEN_MAX)) < 0){ + if(errno == 0) + openmax = OPEN_MAX_GUESS; + else + printf("sysconf error for _SC_OPEN_MAX"); + } + } + + printf("%ld\n", openmax); + +} diff --git a/2/limits/options.c b/2/limits/options.c new file mode 100644 index 0000000..15d9216 --- /dev/null +++ b/2/limits/options.c @@ -0,0 +1,24 @@ +#include +#include +#include + + +int main(void){ + + printf("%ld %d %d\n", _POSIX_ASYNCHRONOUS_IO, _POSIX_JOB_CONTROL, _POSIX_SHELL); + printf("%ld %ld %ld\n", _POSIX_SPIN_LOCKS, _POSIX_THREADS, _POSIX_TIMERS); + printf("%d %ld %d\n", _XOPEN_REALTIME, sysconf(_SC_XOPEN_CRYPT), _XOPEN_SHM); + + if(errno != 0){ + printf("sysconf error for _SC_XOPEN_CRYPT\n"); + } + + printf("%ld\n", pathconf("./openmax.c", _PC_ASYNC_IO)); + if(errno != 0){ + printf("sysconf error for _PC_ASYNC_IO\n"); + } + + printf("%ld\n", pathconf("./openmax.c", _PC_CHOWN_RESTRICTED)); + + return 0; +} diff --git a/2/limits/posix.c b/2/limits/posix.c new file mode 100644 index 0000000..a11e3b9 --- /dev/null +++ b/2/limits/posix.c @@ -0,0 +1,22 @@ +#include +#include + +int main(void){ + + // the length of the args of exec() + printf("%d\n", _POSIX_ARG_MAX); + // the num of child process under a real user id + printf("%d\n", _POSIX_CHILD_MAX); + // some var about file and path + printf("%d %d %d\n", _POSIX_OPEN_MAX, _POSIX_NAME_MAX, _POSIX_PATH_MAX); + // something further + printf("%d %d %d\n", _POSIX_LOGIN_NAME_MAX, _POSIX_MAX_CANON, _POSIX_MAX_INPUT); + // more + printf("%d %d %d\n", _POSIX_SSIZE_MAX, _POSIX_SEM_NSEMS_MAX, _POSIX_TIMER_MAX); + + // different between the real value and define value + printf("%d %d\n", _POSIX_TTY_NAME_MAX, TTY_NAME_MAX); + + return 0; +} + diff --git a/2/limits/xsi.c b/2/limits/xsi.c new file mode 100644 index 0000000..e92d05f --- /dev/null +++ b/2/limits/xsi.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + printf("%d\n", NZERO); + return 0; +}