Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: ssizetype.U,v 3.0.1.3 1997/02/28 16:24:21 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
0065f4af | 4 | ?RCS: |
65a32477 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
959f3c4c JH |
6 | ?RCS: as specified in the README file that comes with the distribution. |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
65a32477 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
959f3c4c JH |
9 | ?RCS: of the source tree for dist 3.0. |
10 | ?RCS: | |
11 | ?RCS: Original Author: Andy Dougherty <doughera@lafcol.lafayette.edu> | |
12 | ?RCS: | |
13 | ?RCS: $Log: ssizetype.U,v $ | |
14 | ?RCS: Revision 3.0.1.3 1997/02/28 16:24:21 ram | |
15 | ?RCS: patch61: integrated perl5 concerns for mis-configured sfio | |
16 | ?RCS: | |
17 | ?RCS: Revision 3.0.1.2 1994/10/29 16:30:28 ram | |
18 | ?RCS: patch36: added ?F: line for metalint file checking | |
19 | ?RCS: patch36: added 'ldflags' to the test compile line (ADO) | |
20 | ?RCS: | |
21 | ?RCS: Revision 3.0.1.1 1994/08/29 16:33:06 ram | |
22 | ?RCS: patch32: created by ADO | |
23 | ?RCS: | |
2cb64bf6 | 24 | ?MAKE:ssizetype: Myread Typedef sizetype cat rm_try Compile run i_stdlib |
959f3c4c JH |
25 | ?MAKE: -pick add $@ %< |
26 | ?S:ssizetype: | |
2cb64bf6 MB |
27 | ?S: This variable defines ssizetype to be something like ssize_t, |
28 | ?S: long or int. It is used by functions that return a count | |
959f3c4c JH |
29 | ?S: of bytes or an error condition. It must be a signed type. |
30 | ?S: We will pick a type such that sizeof(SSize_t) == sizeof(Size_t). | |
31 | ?S:. | |
32 | ?C:SSize_t: | |
33 | ?C: This symbol holds the type used by functions that return | |
34 | ?C: a count of bytes or an error condition. It must be a signed type. | |
35 | ?C: It is usually ssize_t, but may be long or int, etc. | |
36 | ?C: It may be necessary to include <sys/types.h> or <unistd.h> | |
37 | ?C: to get any typedef'ed information. | |
38 | ?C: We will pick a type such that sizeof(SSize_t) == sizeof(Size_t). | |
39 | ?C:. | |
40 | ?H:#define SSize_t $ssizetype /* signed count of bytes */ | |
41 | ?H:. | |
0065f4af | 42 | ?F:!try |
959f3c4c JH |
43 | : see what type is used for signed size_t |
44 | set ssize_t ssizetype int stdio.h sys/types.h | |
45 | eval $typedef | |
46 | dflt="$ssizetype" | |
47 | ?X: Now check out whether sizeof(SSize_t) == sizeof(Size_t) | |
0f00356b | 48 | $cat > try.c <<EOM |
959f3c4c | 49 | #include <stdio.h> |
3b148aa9 JH |
50 | #$i_stdlib I_STDLIB |
51 | #ifdef I_STDLIB | |
52 | #include <stdlib.h> | |
53 | #endif | |
959f3c4c JH |
54 | #include <sys/types.h> |
55 | #define Size_t $sizetype | |
56 | #define SSize_t $dflt | |
57 | int main() | |
58 | { | |
59 | if (sizeof(Size_t) == sizeof(SSize_t)) | |
60 | printf("$dflt\n"); | |
61 | else if (sizeof(Size_t) == sizeof(int)) | |
62 | printf("int\n"); | |
2cb64bf6 | 63 | else |
959f3c4c JH |
64 | printf("long\n"); |
65 | exit(0); | |
66 | } | |
67 | EOM | |
68 | echo " " | |
0f00356b JH |
69 | set try |
70 | if eval $compile_ok && $run ./try > /dev/null; then | |
71 | ssizetype=`$run ./try` | |
959f3c4c JH |
72 | echo "I'll be using $ssizetype for functions returning a byte count." >&4 |
73 | else | |
74 | $cat >&4 <<EOM | |
75 | Help! I can't compile and run the ssize_t test program: please enlighten me! | |
76 | (This is probably a misconfiguration in your system or libraries, and | |
77 | you really ought to fix it. Still, I'll try anyway.) | |
78 | ||
79 | I need a type that is the same size as $sizetype, but is guaranteed to | |
80 | be signed. Common values are ssize_t, int and long. | |
81 | ||
82 | EOM | |
83 | rp="What signed type is the same size as $sizetype?" | |
84 | . ./myread | |
85 | ssizetype="$ans" | |
86 | fi | |
2cb64bf6 | 87 | $rm_try |
959f3c4c | 88 |