Complete Limits.

This commit is contained in:
Saturneric 2020-12-05 09:47:27 +08:00
parent 5c13ef41ee
commit c8a79b8066
7 changed files with 131 additions and 1 deletions

BIN
2/limits/.isoc.c.swp Normal file

Binary file not shown.

39
2/limits/conf.c Normal file
View File

@ -0,0 +1,39 @@
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
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;
}

View File

@ -2,12 +2,22 @@
#include <stdio.h>
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;
}

28
2/limits/openmax.c Normal file
View File

@ -0,0 +1,28 @@
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <stdio.h>
#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);
}

24
2/limits/options.c Normal file
View File

@ -0,0 +1,24 @@
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
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;
}

22
2/limits/posix.c Normal file
View File

@ -0,0 +1,22 @@
#include <limits.h>
#include <stdio.h>
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;
}

7
2/limits/xsi.c Normal file
View File

@ -0,0 +1,7 @@
#include <limits.h>
#include <stdio.h>
int main(void) {
printf("%d\n", NZERO);
return 0;
}