From c8a79b806665d63d3710fc879da0b55b732cac46 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 5 Dec 2020 09:47:27 +0800 Subject: [PATCH] Complete Limits. --- 2/limits/.isoc.c.swp | Bin 0 -> 12288 bytes 2/limits/conf.c | 39 +++++++++++++++++++++++++++++++++++++++ 2/limits/isoc.c | 12 +++++++++++- 2/limits/openmax.c | 28 ++++++++++++++++++++++++++++ 2/limits/options.c | 24 ++++++++++++++++++++++++ 2/limits/posix.c | 22 ++++++++++++++++++++++ 2/limits/xsi.c | 7 +++++++ 7 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 2/limits/.isoc.c.swp create mode 100644 2/limits/conf.c create mode 100644 2/limits/openmax.c create mode 100644 2/limits/options.c create mode 100644 2/limits/posix.c create mode 100644 2/limits/xsi.c diff --git a/2/limits/.isoc.c.swp b/2/limits/.isoc.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..8c9c729abc6e592e1b4b1063799e33900cafbf7a GIT binary patch literal 12288 zcmeI2PfNov7{;S`^$&XR8YiN{*3EetOvI_v6}BqtCLV-Q*KP)8CtW%eQNfSk=h3r% z1pNjc{0f3^+Kx?e=v8?_pXN>Syh-!Bh2}VQpqF??OEW4{jJ;})wcJ>Yy)QE6c%rVl ze=4RWea}_y#J1BN?!H!*q$z#-Lb%PUE6#OSI$p!7JIQpiB~FFxBt@rP*M7C^@P#k} z0wD02fG-<~%y@M*y^>M`^RYQTGhO}cK??*x00ck)1V8`;KmY_l;9nDvXCv%}b~qaC zaw4inzSL0@6$pR;2!H?xfB*=900@8p2!H?xfWRLlVA+guI`m6*@TdR(z4QOuBx5h6 zXVMetj?^S=kY-75WPBjqlWs{}lA5DKLID8~009sH0T2KI5C8!X009sH0U~g9#W?pI zb!VKXvJ{_r!j+As*n-W2=g5u4`Oe;c-l&ywhjCsh?T5jRUd$W0QeL%|vvhFnr?y&@ zOs^ofSllyq!;~o04e}4#l{+%`y+QQVsy-^1)hv`N;iO?S)TkSgF9?R(%&kJM98DO8 z-&uRB2aZj>66gK2fh;1(Pc7jtb=$&TzN8Dj!mYP_+u>^+X^XaYvOdri-nCbKAC +#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; +}