-
Notifications
You must be signed in to change notification settings - Fork 0
/
e_param.c
1894 lines (1368 loc) · 79.9 KB
/
e_param.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////////
//
// This file is to define all common and regular parameters in Unix
//
//
#include <stdio.h>
#include <time.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <netdb.h>
#include "i_utils.h"
int main()
{
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "THE FOLLOWING CONTENT IS GENERATED FROM e_param.c");
printf( "%-6s%s\n", "!", "EDITTING IT YOU'LL GET WHAT YOU ARE DESERVED.");
printf( "%-6s%s\n", "!", "" );
const char *fmt1 = "%-6sinteger,parameter :: %-13s = %2d\n" ;
const char *fst1 = "%-6s%s";
//
printf( "%-6s%s\n", "!", "" ) ;
printf( "%-6s%s\n", "!", "character(len=1,kind=ck_char) :: ???" );
printf( "%-6s%s\n", "!", "" ) ;
printf( fmt1, "", "ck_char", (int) sizeof(char) );
printf( fmt1, "", "ck_signed_char", (int) sizeof(signed char) );
// Fortran does not have this kind, use integer(kind=2) instead. OK?
// printf( fmt1, "", "ck_unsigned_char", (int) sizeof(unsigned char) );
//
printf( "%-6s%s\n", "!", "" ) ;
printf( "%-6s%s\n", "!", "logical(kind=ck_bool) ::" );
printf( "%-6s%s\n", "!", "" ) ;
printf( fmt1, "", "ck_bool", (int) sizeof(_Bool) );
//
printf( "%-6s%s\n", "!", "" ) ;
printf( "%-6s%s\n", "!", "integer(kind=ck_...) ::" );
printf( "%-6s%s\n", "!", "" ) ;
printf( fmt1, "", "ck_int", (int) sizeof(int) );
printf( fmt1, "", "ck_short", (int) sizeof(short int) );
printf( fmt1, "", "ck_long", (int) sizeof(long) );
printf( fmt1, "", "ck_long_int", (int) sizeof(long int) );
printf( fmt1, "", "ck_long_long", (int) sizeof(long long int) );
//
printf( "%-6s%s\n", "!", "" ) ;
printf( "%-6s%s\n", "!", "real(kind=ck_...) ::" );
printf( "%-6s%s\n", "!", "" ) ;
printf( fmt1, "", "ck_float", (int) sizeof(float) );
printf( fmt1, "", "ck_double", (int) sizeof(double) );
printf( fmt1, "", "ck_long_double", (int) sizeof(long double) );
//
printf( "%-6s%s\n", "!", "" ) ;
printf( "%-6s%s\n", "!", "complex(kind=ck_...) ::" );
printf( "%-6s%s\n", "!", "" ) ;
printf( fmt1, "", "ck_float_complex", (int) sizeof(float _Complex) );
printf( fmt1, "", "ck_double_complex", (int) sizeof(double _Complex) );
printf( fmt1, "", "ck_long_double_complex", (int) sizeof(long double _Complex) );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define constant mode_t for mkdir, mkfifo" );
printf( "%-6s%s\n", "!", "Define constants for stat from <sys/stat.h>" );
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_mode_t", sizeof(mode_t) );
printf( fmt1, "", "ck_time_t", (int) sizeof(time_t) );
printf( fmt1, "", "ck_clock_t", sizeof(clock_t) );
printf( fmt1, "", "ck_uid_t", sizeof(uid_t) );
printf( fmt1, "", "ck_gid_t", sizeof(gid_t) );
printf( fmt1, "", "ck_pid_t", sizeof(pid_t) );
printf( fmt1, "", "ck_size_t", sizeof(size_t) );
printf( fmt1, "", "ck_ssize_t", sizeof(ssize_t) );
// printf( fmt1, "", "ck_null", NULL );
// printf( fmt1, "", "ck_l_ctermid", L_ctermid );
printf( fmt1, "", "ck_dev_t", sizeof(dev_t) );
printf( fmt1, "", "ck_ino_t", sizeof(ino_t) );
printf( fmt1, "", "ck_off_t", sizeof(off_t) );
printf( fmt1, "", "ck_nlink_t", sizeof(nlink_t) );
printf( fmt1, "", "ck_blksize_t", sizeof(blksize_t) );
printf( fmt1, "", "ck_blkcnt_t", sizeof(blkcnt_t) );
printf( fmt1, "", "ck_fpos_t", sizeof(fpos_t) );
// printf( fmt1, "", "ck_va_list", sizeof(va_list) );
printf( fmt1, "", "ck_null", NULL );
printf( fmt1, "", "ck_intmax_t", sizeof(intmax_t) );
//
//
// NOTE ON POINTER IMPLEMENTAIONIN IN FORTRAN. Make sure that:
//
// sizeof(intptr_t) = sizeof(DIR *) ) = sizeof(FILE *)
//
// which all return 8 (in byte). Or, use use INTEGER(8) for storing pointer
// references. In Fotran lib, I use INTEGER(kind=intptr_t) for all pointers
// (FILE *), (DIR *), anf for any other pointers.
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define void* pointer in C language," );
printf( "%-6s%s\n", "!", "where intptr_t (=8) is from #include <stdint.h>" );
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_intptr_t", sizeof(intptr_t) );
printf( fst1, "", "type ck_voidptr \n" );
// printf( fst1, "", " private \n" ); // turn on in a module.
printf( fst1, "", " integer(kind = ck_intptr_t) :: ptr \n" );
printf( fst1, "", "end type ck_voidptr \n" );
printf( fst1, "", "type(ck_voidptr),parameter :: ck_nullptr = ck_voidptr(0)\n" );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define stat from <stat/stat.h>, i.e. <bits/stat.h>" );
printf( "%-6s%s\n", "!", "" );
printf( fst1, "", "type ck_stat \n" );
// printf( fst1, "", " private \n" ); // turn on in a module.
printf( fst1, "", " integer(kind = ck_dev_t) :: st_dev \n" );
printf( fst1, "", " integer(kind = ck_ino_t) :: st_ino \n" );
printf( fst1, "", " integer(kind = ck_mode_t) :: st_mode \n" );
printf( fst1, "", " integer(kind = ck_nlink_t) :: st_nlink \n" );
printf( fst1, "", " integer(kind = ck_uid_t) :: st_uid \n" );
printf( fst1, "", " integer(kind = ck_gid_t) :: st_gid \n" );
printf( fst1, "", " integer(kind = ck_dev_t) :: st_rdev \n" );
printf( fst1, "", " integer(kind = ck_off_t) :: st_size \n" );
printf( fst1, "", " integer(kind = ck_time_t) :: st_atime \n" );
printf( fst1, "", " integer(kind = ck_time_t) :: st_mtime \n" );
printf( fst1, "", " integer(kind = ck_time_t) :: st_ctime \n" );
printf( fst1, "", " integer(kind = ck_blksize_t) :: st_blksize \n" );
printf( fst1, "", " integer(kind = ck_blkcnt_t) :: st_blocks \n" );
printf( fst1, "", "end type ck_stat\n" );
printf( "%-6s%s\n", "!", "" );
//
//
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck__sc_arg_max", _SC_ARG_MAX );
printf( fmt1, "", "ck__sc_child_max", _SC_CHILD_MAX );
printf( fmt1, "", "ck__sc_host_name_max", _SC_HOST_NAME_MAX );
printf( fmt1, "", "ck__sc_login_name_max", _SC_LOGIN_NAME_MAX );
printf( fmt1, "", "ck__sc_clk_tck", _SC_CLK_TCK );
printf( fmt1, "", "ck__sc_open_max", _SC_OPEN_MAX );
printf( fmt1, "", "ck__sc_pagesize", _SC_PAGESIZE );
printf( fmt1, "", "ck__sc_re_dup_max", _SC_RE_DUP_MAX );
printf( fmt1, "", "ck__sc_stream_max", _SC_STREAM_MAX );
printf( fmt1, "", "ck__sc_symloop_max", _SC_SYMLOOP_MAX );
printf( fmt1, "", "ck__sc_tty_name_max", _SC_TTY_NAME_MAX );
printf( fmt1, "", "ck__sc_tzname_max", _SC_TZNAME_MAX );
printf( fmt1, "", "ck__sc_version", _SC_VERSION );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define the DIR * handler:" );
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_dirptr", sizeof(DIR *) );
printf( fst1, "", "type ck_dir \n" );
// printf( fst1, "", " private \n" ); // turn on in a module.
printf( fst1, "", " integer(kind = ck_dirptr) :: ptr \n" );
// printf( fst1, "", " integer(kind = ck_intptr_t) :: ptr \n" );
printf( fst1, "", "end type ck_dir \n" );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define the FILE handler:" );
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_fileptr", sizeof(FILE *) );
printf( fst1, "", "type ck_file \n" );
// printf( fst1, "", " private \n" ); // turn on in a module.
printf( fst1, "", " integer(kind = ck_fileptr) :: ptr \n" );
// printf( fst1, "", " integer(kind = ck_intptr_t) :: ptr \n" );
printf( fst1, "", "end type ck_file \n" );
printf( fmt1, "", "ck_eof", EOF );
printf( fmt1, "", "ck_seek_set", SEEK_SET );
printf( fmt1, "", "ck_seek_cur", SEEK_CUR );
printf( fmt1, "", "ck_seek_end", SEEK_END );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define constants for File" );
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_f_ok", F_OK );
printf( fmt1, "", "ck_r_ok", R_OK );
printf( fmt1, "", "ck_w_ok", W_OK );
printf( fmt1, "", "ck_x_ok", X_OK );
printf( fmt1, "", "ck_s_irusr", S_IRUSR );
printf( fmt1, "", "ck_s_iwusr", S_IWUSR );
printf( fmt1, "", "ck_s_ixusr", S_IXUSR );
printf( fmt1, "", "ck_s_irwxu", S_IRWXU );
printf( fmt1, "", "ck_s_irgrp", S_IRGRP );
printf( fmt1, "", "ck_s_iwgrp", S_IWGRP );
printf( fmt1, "", "ck_s_ixgrp", S_IXGRP );
printf( fmt1, "", "ck_s_irwxg", S_IRWXG );
printf( fmt1, "", "ck_s_iroth", S_IROTH );
printf( fmt1, "", "ck_s_iwoth", S_IWOTH );
printf( fmt1, "", "ck_s_ixoth", S_IXOTH );
printf( fmt1, "", "ck_s_irwxo", S_IRWXO );
printf( fmt1, "", "ck_s_isgid", S_ISGID );
printf( fmt1, "", "ck_s_isuid", S_ISUID );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define some constants in <linux/limits.h>" );
printf( "%-6s%s\n", "!", "Note: <i_utils.h> re-defines the names" );
printf( "%-6s%s\n", "!", " MAXLEN_PATHNAME := PATH_MAX" );
printf( "%-6s%s\n", "!", " MAXLEN_FILENAME := NAME_MAX" );
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_path_max", MAXLEN_PATHNAME );
printf( fmt1, "", "ck_name_max", MAXLEN_FILENAME );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "ASCII:" );
printf( "%-6s%s\n", "!", "" );
const char *fmt2 =
"%-6sinteger,parameter :: %-12s = %3d ! %s\n" ;
printf( fmt2, "", "ck_icha_nul", 0, "NULL char" );
printf( fmt2, "", "ck_icha_soh", 1, "Start Of Heading" );
printf( fmt2, "", "ck_icha_stx", 2, "Start of TeXt" );
printf( fmt2, "", "ck_icha_etx", 3, "End of TeXt" );
printf( fmt2, "", "ck_icha_eot", 4, "End Of Transmission" );
printf( fmt2, "", "ck_icha_enq", 5, "ENQuiry" );
printf( fmt2, "", "ck_icha_ack", 6, "Acknowledge" );
printf( fmt2, "", "ck_icha_bel", '\a', "Alert, Bell" );
printf( fmt2, "", "ck_icha_bs ", '\b', "Back Space" );
printf( fmt2, "", "ck_icha_ff ", '\f', "New Page, Form Feed" );
printf( fmt2, "", "ck_icha_lf ", '\n', "New Line, Line Feed" );
printf( fmt2, "", "ck_icha_cr ", '\r', "Carriage Return" );
printf( fmt2, "", "ck_icha_tab", '\t', "Horizontal Tab" );
printf( fmt2, "", "ck_icha_vt ", '\v', "Vertical Tab" );
printf( fmt2, "", "ck_icha_sub", 26, "Substitute" );
printf( fmt2, "", "ck_icha_esc", 27, "Escape" );
printf( fmt2, "", "ck_icha_fs ", 28, "File Separator" );
printf( fmt2, "", "ck_icha_gs ", 29, "Group Separator" );
printf( fmt2, "", "ck_icha_rs ", 30, "Record Separator" );
printf( fmt2, "", "ck_icha_us ", 31, "Unit Separator" );
printf( "%-6s%s\n", "!", "" );
const char *fmt3 =
"%-6scharacter(len=1),parameter :: %-12s = achar(%3d) ! %s\n" ;
printf( fmt3, "", "ck_char_nul", 0, "NULL char" );
printf( fmt3, "", "ck_char_soh", 1, "Start Of Heading" );
printf( fmt3, "", "ck_char_stx", 2, "Start of TeXt" );
printf( fmt3, "", "ck_char_etx", 3, "End of TeXt" );
printf( fmt3, "", "ck_char_eot", 4, "End Of Transmission" );
printf( fmt3, "", "ck_char_enq", 5, "ENQuiry" );
printf( fmt3, "", "ck_char_ack", 6, "Acknowledge" );
printf( fmt3, "", "ck_char_bel", '\a', "Alert, Bell" );
printf( fmt3, "", "ck_char_bs ", '\b', "Back Space" );
printf( fmt3, "", "ck_char_ff ", '\f', "New Page, Form Feed" );
printf( fmt3, "", "ck_char_lf ", '\n', "New Line, Line Feed" );
printf( fmt3, "", "ck_char_cr ", '\r', "Carriage Return" );
printf( fmt3, "", "ck_char_tab", '\t', "Horizontal Tab" );
printf( fmt3, "", "ck_char_vt ", '\v', "Vertical Tab" );
printf( fmt3, "", "ck_char_sub", 26, "Substitute" );
printf( fmt3, "", "ck_char_esc", 27, "Escape" );
printf( fmt3, "", "ck_char_fs ", 28, "File Separator" );
printf( fmt3, "", "ck_char_gs ", 29, "Group Separator" );
printf( fmt3, "", "ck_char_rs ", 30, "Record Separator" );
printf( fmt3, "", "ck_char_us ", 31, "Unit Separator" );
//
printf( "%-6s%s\n", "!", "" );
printf( "%-6s%s\n", "!", "Define some constants for Networking" ) ;
printf( "%-6s%s\n", "!", " #include <stdint.h>" ) ;
printf( "%-6s%s\n", "!", "" );
printf( fmt1, "", "ck_uint16_t", sizeof(uint16_t) );
printf( fmt1, "", "ck_uint32_t", sizeof(uint32_t) );
printf( fmt1, "", "ck_hostentptr", sizeof(struct hostent *) );
//
//
printf( "%-6s%s\n", "!", "" );
return 0;
}
/*
#include <stdio.h>
/usr/include/stdio.h
+ printf, fprintf, vprintf, vfprintf, putc, fputc,
gets, fgets
+ fopen, fclose, fread, fwrite,
#include <dirent.h>
/usr/include/dirent.h
+ DIR
This is the data type of directory stream objects.
The actual structure is opaque to users.
typedef struct __dirstream DIR;
+ opendir, readdir, closedir, rewinddir, seekdir, ...
#include <time.h>
/usr/include/time.h
+ clock_t, time_t,
+ clock,
clock_t clock ( void ) ;
Time used by the program so far (user time + system time).
The result / CLOCKS_PER_SEC is program time in seconds,
where CLOCKS_PER_SEC is constant defined in <bits/time.h>, i.e.
/usr/include/x86_64-linux-gnu/bits/time.h
+ time,
time_t time ( time_t *timer )
Return the current time and put it in *TIMER if TIMER is not NULL.
+ difftime,
double difftime ( time_t time1, time_t time0 )
Return the difference between TIME1 and TIME0.
+ mktime,
time_t mktime (struct tm *tp)
Return the 'time_t' representation of TP and normalize TP.
+ strftime ( char *s, size_t maxsize, const char *format, const struct tm *tp )
Format TP into S according to FORMAT.
Write no more than MAXSIZE characters and return the number
of characters written, or 0 if it would exceed MAXSIZE.
+ gmtime,
struct tm *gmtime ( const time_t *timer )
Return the 'struct tm' representation of *TIMER in Universal
Coordinated Time (aka Greenwich Mean Time).
+ localtime,
struct tm *localtime ( const time_t *timer )
Return the 'struct tm' representation of *TIMER in the local timezone.
#include <sys/types.h>
/usr/include/x86_64-linux-gnu/sys/types.h
+ #include <bits/types.h> --> For __mode_t and __dev_t.
+ pid_t, uid_t, gid_t, dev_t, mode_t, nlink_t,
u_char, u_short, u_int, u_long, quad_t, u_quad_t, fsid_t,
off_t, ino_t,
#include <sys/stat.h>
/usr/include/x86_64-linux-gnu/sys/stat.h
+ #include <bits/types.h> --> For __mode_t and __dev_t.
+ mode_t, dev_t, gid_t, ino_t,
+ mkdir, mkfifo,
+ chmod,
int chmod ( const char * FILE, mode_t MODE )
Set file access permissions for FILE to MODE.
If FILE is a symbolic link, this affects its target instead.
+ umask
mode_t umask ( mode_t cmask )
Set the file creation mask of the current process to MASK,
and return the old creation mask.
+ #include <bits/stat.h>
/usr/include/x86_64-linux-gnu/bits/stat.h
--> For definition of
struct stat
{
dev_t st_dev device number of filesystem.
ino_t st_ino inode number.
mode_t st_mode file mode (type and permissions). (in decimal value)
nlink_t st_nlink number of (hard) links to the file.
uid_t st_uid numeric user ID of file's owner.
gid_t st_gid numeric group ID of file's owner.
dev_t st_rdev the device identifier (special files only).
off_t st_size total size of file, in bytes.
time_t st_atime last access time in seconds since the epoch.
time_t st_mtime last modify time in seconds since the epoch.
time_t st_ctime inode change time in seconds since the epoch (*).
Not all fields are supported on all filesystem types.
Notably, the ctime field is non-portable.
blksize_t st_blksize preferred I/O size in bytes for interacting with the
file (may vary from file to file).
blkcnt_t st_blocks actual number of system-specific blocks allocated
on disk (often, but not always, 512 bytes each).
}
+
+ S_IRGRP Read by group.
+ S_IWGRP Write by group.
+ S_IXGRP Execute by group.
+ S_IRWXG Read, write, and execute by group.
+ S_IROTH Read by others.
+ S_IWOTH Write by others.
+ S_IXOTH Execute by others.
+ S_IRWXO Read, write, and execute by others.
+ S_IRUSR Read by owner.
+ S_IWUSR Write by owner.
+ S_IXUSR Execute by owner.
+ S_IRWXU Read, write, and execute by owner.
+ S_ISUID Set user ID on execution.
+ S_ISGID Set group ID on execution
+
+ S_ISDIR (mode) __S_ISTYPE((mode), __S_IFDIR)
+ S_ISCHR (mode) __S_ISTYPE((mode), __S_IFCHR)
+ S_ISBLK (mode) __S_ISTYPE((mode), __S_IFBLK)
+ S_ISREG (mode) __S_ISTYPE((mode), __S_IFREG)
+ S_ISFIFO (mode) __S_ISTYPE((mode), __S_IFIFO)
+ S_ISLNK (mode) __S_ISTYPE((mode), __S_IFLNK)
+ stat
The stat() function shall obtain information about the named file and
write it to the area pointed to by the buf argument. The path argument
points to a pathname naming a file. Read, write, or execute permission of
the named file is not required. An implementation that provides additional
or alternate file access control mechanisms may, under
implementation-defined conditions, cause stat() to fail. In particular,
the system may deny the existence of the file specified by path.
If the named file is a symbolic link, the stat() function shall
continue pathname resolution using the contents of the symbolic link,
and shall return information pertaining to the resulting file if the
file exists.
+ lstat
The lstat() function shall be equivalent to stat(), except when path
refers to a symbolic link. In that case lstat() shall return information
about the link, while stat() shall return information about the file the
link references.
#include <unistd.h>
/usr/include/unistd.h POSIX Standard: 2.10 Symbolic Constants
+ R_OK = 4 Test for read permission.
+ W_OK = 2 Test for write permission.
+ X_OK = 1 Test for execute permission.
+ F_OK = 0 Test for existence.
+ access,
int access (const char *name, int type)
Test for access to NAME using the real UID and real GID.
+ close,
+ read,
+ write,
+ pread
Read NBYTES into BUF from FD at the given position OFFSET without
changing the file pointer. Return the number read, -1 for errors
or 0 for EOF.
+ pwrite
Write N bytes of BUF to FD at the given position OFFSET without
changing the file pointer. Return the number written, or -1.
+ pipe
Create a one-way communication channel (pipe).
If successful, two file descriptors are stored in PIPEDES;
bytes written on PIPEDES[1] can be read from PIPEDES[0].
Returns 0 if successful, -1 if not.
+ sleep
+ chown,
+ chdir,
+ getcwd,
+ execve, execv,
+ pathconf, fpathconf, sysconf,
+ getpid, getppid, getpgrp, __getpgid,
+ setpgid, setpgrp, setsid,
+ getuid, geteuid, getgid, getegid, getgroups,
+ setuid, setgid,
+ fork,
+ ttyname, isatty,
+ link, symlink, unlink,
+ rmdir,
+ tcgetpgrp, tcsetpgrp,
+ getlogin,
+ fsync,
+ #include <bits/types.h> --> /usr/include/x86_64-linux-gnu/bits/types.h
+ readlink
ssize_t readlink( const char *path, char *buf, size_t bufsize )
The readlink() function shall place the contents of the symbolic link
referred to by PATH in the buffer BUF which has size BUFSIZE. If the number
of bytes in the symbolic link is less than BUFSIZE, the contents of the
remainder of BUF are unspecified. If the BUF argument is not large enough
to contain the link content, the first BUFSIZE bytes shall be placed in BUF.
If the value of BUFSIZE is greater than {SSIZE_MAX}, the result is
implementation-defined.
Upon successful completion, readlink() shall mark for update the last
data access timestamp of the symbolic link.
RETURN VALUE:
Upon successful completion, these functions shall return
the count of bytes placed in the buffer.
Otherwise, these functions shall return a value of
-1
leave the buffer unchanged, and set ERRNO to indicate the error.
ERRORS:
[EACCES]
Search permission is denied for a component of the path prefix of PATH.
[EINVAL]
The PATH argument names a file that is not a symbolic link.
[EIO]
An I/O error occurred while reading from the file system.
[ELOOP]
A loop exists in symbolic links encountered during resolution of the PATH
argument.
[ENAMETOOLONG]
The length of a component of a pathname is longer than {NAME_MAX}.
[ENOENT]
A component of PATH does not name an existing file or PATH is an empty
string.
[ENOTDIR]
A component of the PATH prefix names an existing file that is neither a
directory nor a symbolic link to a directory, or the PATH argument
contains at least one non- <slash> character and ends with one or more
trailing <slash> characters and the last pathname component names an
existing file that is neither a directory nor a symbolic link to a
directory.
REF:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html
#include <linux/limits.h>
/usr/include/linux/limits.h
+ PATH_MAX = 4096
chars in a path name including nul,
+ NAME_MAX = 255
chars in a file name,
+ LINK_MAX = 127
links a file may have
+ ARG_MAX = 131072
bytes of args + environ for exec()
#include <stdlib.h>
/usr/include/stdlib.h
+ realpath
char *realpath ( const char *file_name, char *resolved_name )
Return the canonical absolute name of FILE_NAME. If RESOLVED_NAME
is null, the result is malloc'd; otherwise, if the canonical name is
PATH_MAX chars or more, returns null with 'errno' set to ENAMETOOLONG;
if the name fits in fewer than PATH_MAX chars, returns the name in
RESOLVED.
Upon successful completion, realpath() shall return a pointer to
the resolved name. Otherwise, realpath() shall return a null pointer
and set errno to indicate the error, and the contents of the buffer
pointed to by resolved_name are undefined.
ERRORS
The realpath() function shall fail if:
[EACCES]
Read or search permission was denied for a component of file_name.
[EINVAL]
The file_name argument is a null pointer.
[EIO]
An error occurred while reading from the file system.
[ELOOP]
A loop exists in symbolic links encountered during resolution of the
file_name argument.
[ENAMETOOLONG]
The length of the file_name argument exceeds {PATH_MAX} or a pathname
component is longer than {NAME_MAX}.
[ENOENT]
A component of file_name does not name an existing file or file_name
points to an empty string.
[ENOTDIR]
A component of the path prefix is not a directory.
The realpath() function may fail if:
[ELOOP]
More than {SYMLOOP_MAX} symbolic links were encountered during resolution
of the file_name argument.
[ENAMETOOLONG]
Pathname resolution of a symbolic link produced an intermediate result
whose length exceeds {PATH_MAX}.
[ENOMEM]
Insufficient storage space is available.
#include <stdint.h>
/usr/include/stdint.h
Here below 8,16,32,64 are the numbers of Bits, 8 bit = 1 byte, 64 bit = 8 byte
+ int8_t, int16_t, int32_t, int64_t,
+ uint8_t, uint16_t, uint32_t, uint64_t,
+ int_least8_t, int_least16_t, int_least32_t, int_least64_t,
+ uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t,
+ intptr_t
integer value of size of reference (pointer, address)
integer(kind=intptr_t) :: xref
+ uintptr_t,
+ intmax_t, uintmax_t,
#include <netdb.h>
/usr/include/netdb.h
+ Description of data base entry for a single host
struct hostent
{
char *h_name; // Official name of host.
char **h_aliases; // Alias list.
int h_addrtype; // Host address type.
int h_length; // Length of address.
char **h_addr_list; // List of addresses from name server.
};
+ void sethostent (int __stay_open);
+ void endhostent (void);
+ struct hostent *gethostent (void);
+ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type );
+ struct hostent *gethostbyname (const char *name );
+ void setnetent (int stay_open);
+ void endnetent (void);
+ struct netent *getnetent (void);
wherein the description of data base entry for a single network:
struct netent
{
char *n_name; // Official name of network. //
char **n_aliases; // Alias list. //
int n_addrtype; // Net address type. //
uint32_t n_net; // Network number. //
};
was defined in #include <bits/netdb.h>
/usr/include/x86_64-linux-gnu/bits/netdb.h
But, never include <bits/netdb.h> directly; use <netdb.h> instead.
+ struct netent *getnetbyaddr (uint32_tnet, int type);
+ struct netent *getnetbyname (const char *name);
+ Description of data base entry for a single service
struct servent
{
char *s_name; // Official service name. //
char **s_aliases; // Alias list. //
int s_port; // Port number. //
char *s_proto; // Protocol to use. //
};
+ void setservent (int __stay_open) ;
+ void endservent (void);
+ struct servent *getservent (void);
+ struct servent *getservbyname (const char *__name, const char *__proto);
+ struct servent *getservbyport (int __port, const char *__proto);
+ Description of data base entry for a single service
struct protoent
{
char *p_name; // Official protocol name.
char **p_aliases; // Alias list.
int p_proto; // Protocol number.
};
+ void setprotoent (int __stay_open);
+ void endprotoent (void);
+ struct protoent *getprotoent (void);
+ struct protoent *getprotobyname (const char *__name);
+ struct protoent *getprotobynumber (int __proto);
+
+
#include <sys/socket.h>
/usr/include/x86_64-linux-gnu/sys/socket.h
+ int accept (
int socket, struct sockaddr *restrict address, socklen_t *address_len );
*/
////////////////////////////////////////////////////////////////////////////////
/*
*** NAME:
getlogin, getlogin_r - get login name
SYNOPSIS
#include <unistd.h>
char *getlogin(void);
int getlogin_r(char *name, size_t namesize);
DESCRIPTION
The getlogin() function shall return a pointer to a string containing the user name associated by the login activity with the controlling terminal of the current process. If getlogin() returns a non-null pointer, then that pointer points to the name that the user logged in under, even if there are several login names with the same user ID.
The getlogin() function need not be thread-safe.
The getlogin_r() function shall put the name associated by the login activity with the controlling terminal of the current process in the character array pointed to by name. The array is namesize characters long and should have space for the name and the terminating null character. The maximum size of the login name is {LOGIN_*** NAME:_MAX}.
If getlogin_r() is successful, name points to the name the user used at login, even if there are several login names with the same user ID.
The getlogin() and getlogin_r() functions may make use of file descriptors 0, 1, and 2 to find the controlling terminal of the current process, examining each in turn until the terminal is found. If in this case none of these three file descriptors is open to the controlling terminal, these functions may fail. The method used to find the terminal associated with a file descriptor may depend on the file descriptor being open to the actual terminal device, not /dev/tty.
RETURN VALUE
Upon successful completion, getlogin() shall return a pointer to the login name or a null pointer if the user's login name cannot be found. Otherwise, it shall return a null pointer and set errno to indicate the error.
The application shall not modify the string returned. The returned pointer might be invalidated or the string content might be overwritten by a subsequent call to getlogin(). The returned pointer and the string content might also be invalidated if the calling thread is terminated.
If successful, the getlogin_r() function shall return zero; otherwise, an error number shall be returned to indicate the error.
ERRORS
These functions may fail if:
[EMFILE]
All file descriptors available to the process are currently open.
[ENFILE]
The maximum allowable number of files is currently open in the system.
[ENOTTY]
None of the file descriptors 0, 1, or 2 is open to the controlling terminal of the current process.
[ENXIO]
The calling process has no controlling terminal.
The getlogin_r() function may fail if:
[ERANGE]
The value of namesize is smaller than the length of the string to be returned including the terminating null character.
The following sections are informative.
EXAMPLES
Getting the User Login Name
The following example calls the getlogin() function to obtain the name of the user associated with the calling process, and passes this information to the getpwnam() function to get the associated user database information.
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
...
char *lgn;
struct passwd *pw;
...
if ((lgn = getlogin()) == NULL || (pw = getpwnam(lgn)) == NULL) {
fprintf(stderr, "Get of user information failed.\n"); exit(1);
}
APPLICATION USAGE
Three names associated with the current process can be determined: getpwuid(geteuid()) shall return the name associated with the effective user ID of the process; getlogin() shall return the name associated with the current login activity; and getpwuid(getuid()) shall return the name associated with the real user ID of the process.
The getlogin_r() function is thread-safe and returns values in a user-supplied buffer instead of possibly using a static data area that may be overwritten by each call.
RATIONALE
The getlogin() function returns a pointer to the user's login name. The same user ID may be shared by several login names. If it is desired to get the user database entry that is used during login, the result of getlogin() should be used to provide the argument to the getpwnam() function. (This might be used to determine the user's login shell, particularly where a single user has multiple login shells with distinct login names, but the same user ID.)
The information provided by the cuserid() function, which was originally defined in the POSIX.1-1988 standard and subsequently removed, can be obtained by the following:
getpwuid(geteuid())
while the information provided by historical implementations of cuserid() can be obtained by:
getpwuid(getuid())
The thread-safe version of this function places the user name in a user-supplied buffer and returns a non-zero value if it fails. The non-thread-safe version may return the name in a static data area that may be overwritten by each call.
*/
/*
*** NAME:
gethostname - get name of current host
SYNOPSIS
#include <unistd.h>
int gethostname(char *name, size_t namelen);
DESCRIPTION
The gethostname() function shall return the standard host name for the current machine. The namelen argument shall specify the size of the array pointed to by the name argument. The returned name shall be null-terminated, except that if namelen is an insufficient length to hold the host name, then the returned name shall be truncated and it is unspecified whether the returned name is null-terminated.
Host names are limited to {HOST_*** NAME:_MAX} bytes.
RETURN VALUE
Upon successful completion, 0 shall be returned; otherwise, -1 shall be returned.
*/
/*
*** NAME:
getppid - get the parent process ID
SYNOPSIS
#include <unistd.h>
pid_t getppid(void);
DESCRIPTION
The getppid() function shall return the parent process ID of the calling process.
RETURN VALUE
The getppid() function shall always be successful and no return value is reserved to indicate an error.
*** NAME:
getsockopt - get the socket options
SYNOPSIS
#include <sys/socket.h>
int getsockopt(int socket, int level, int option_name,
void *restrict option_value, socklen_t *restrict option_len);
DESCRIPTION
The getsockopt() function manipulates options associated with a socket.
The getsockopt() function shall retrieve the value for the option specified by the option_name argument for the socket specified by the socket argument. If the size of the option value is greater than option_len, the value stored in the object pointed to by the option_value argument shall be silently truncated. Otherwise, the object pointed to by the option_len argument shall be modified to indicate the actual length of the value.
The level argument specifies the protocol level at which the option resides. To retrieve options at the socket level, specify the level argument as SOL_SOCKET. To retrieve options at other levels, supply the appropriate level identifier for the protocol controlling the option. For example, to indicate that an option is interpreted by the TCP (Transmission Control Protocol), set level to IPPROTO_TCP as defined in the <netinet/in.h> header.
The socket in use may require the process to have appropriate privileges to use the getsockopt() function.
The option_name argument specifies a single option to be retrieved. It can be one of the socket-level options defined in <sys/socket.h> and described in Use of Options.
RETURN VALUE
Upon successful completion, getsockopt() shall return 0; otherwise, -1 shall be returned and errno set to indicate the error.
ERRORS
The getsockopt() function shall fail if:
[EBADF]
The socket argument is not a valid file descriptor.
[EINVAL]
The specified option is invalid at the specified socket level.
[ENOPROTOOPT]
The option is not supported by the protocol.
[ENOTSOCK]
The socket argument does not refer to a socket.
The getsockopt() function may fail if:
[EACCES]
The calling process does not have appropriate privileges.
[EINVAL]
The socket has been shut down.
[ENOBUFS]
Insufficient resources are available in the system to complete the function.
*** NAME:
getsubopt - parse suboption arguments from a string
SYNOPSIS
[CX] [Option Start] #include <stdlib.h>
int getsubopt(char **optionp, char * const *keylistp, char **valuep); [Option End]
DESCRIPTION
The getsubopt() function shall parse suboption arguments in a flag argument. Such options often result from the use of getopt().
The getsubopt() argument optionp is a pointer to a pointer to the option argument string. The suboption arguments shall be separated by <comma> characters and each may consist of either a single token, or a token-value pair separated by an <equals-sign>.
The keylistp argument shall be a pointer to a vector of strings. The end of the vector is identified by a null pointer. Each entry in the vector is one of the possible tokens that might be found in *optionp. Since <comma> characters delimit suboption arguments in optionp, they should not appear in any of the strings pointed to by keylistp. Similarly, because an <equals-sign> separates a token from its value, the application should not include an <equals-sign> in any of the strings pointed to by keylistp. The getsubopt() function shall not modify the keylistp vector.
The valuep argument is the address of a value string pointer.
If a <comma> appears in optionp, it shall be interpreted as a suboption separator. After <comma> characters have been processed, if there are one or more <equals-sign> characters in a suboption string, the first <equals-sign> in any suboption string shall be interpreted as a separator between a token and a value. Subsequent <equals-sign> characters in a suboption string shall be interpreted as part of the value.
If the string at *optionp contains only one suboption argument (equivalently, no <comma> characters), getsubopt() shall update *optionp to point to the null character at the end of the string. Otherwise, it shall isolate the suboption argument by replacing the <comma> separator with a null character, and shall update *optionp to point to the start of the next suboption argument. If the suboption argument has an associated value (equivalently, contains an <equals-sign>), getsubopt() shall update *valuep to point to the value's first character. Otherwise, it shall set *valuep to a null pointer. The calling application may use this information to determine whether the presence or absence of a value for the suboption is an error.
Additionally, when getsubopt() fails to match the suboption argument with a token in the keylistp array, the calling application should decide if this is an error, or if the unrecognized option should be processed in another way.
RETURN VALUE
The getsubopt() function shall return the index of the matched token string, or -1 if no token strings were matched.
ERRORS
No errors are defined.
The following sections are informative.
EXAMPLES
Parsing Suboptions
The following example uses the getsubopt() function to parse a value argument in the optarg external variable returned by a call to getopt().
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int do_all;
const char *type;
int read_size;
int write_size;
int read_only;
enum
{
RO_OPTION = 0,
RW_OPTION,
READ_SIZE_OPTION,
WRITE_SIZE_OPTION
};
const char *mount_opts[] =
{
[RO_OPTION] = "ro",
[RW_OPTION] = "rw",
[READ_SIZE_OPTION] = "rsize",
[WRITE_SIZE_OPTION] = "wsize",
NULL
};
int
main(int argc, char *argv[])
{
char *subopts, *value;
int opt;
while ((opt = getopt(argc, argv, "at:o:")) != -1)
switch(opt)
{
case 'a':
do_all = 1;
break;
case 't':
type = optarg;
break;
case 'o':
subopts = optarg;
while (*subopts != ' ')
{
char *saved = subopts;
switch(getsubopt(&subopts, (char **)mount_opts,
&value))
{
case RO_OPTION:
read_only = 1;
break;
case RW_OPTION:
read_only = 0;
break;
case READ_SIZE_OPTION:
if (value == NULL)
abort();
read_size = atoi(value);
break;
case WRITE_SIZE_OPTION:
if (value == NULL)
abort();
write_size = atoi(value);
break;
default:
// Unknown suboption. //
printf("Unknown suboption `%s'\n", saved);
abort();
}
}
break;
default:
abort();
}
// Do the real work. //
return 0;
}