Rev 4921 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4921 | Rev 6536 | ||
---|---|---|---|
Line 37... | Line 37... | ||
37 | _VOID |
37 | _VOID |
38 | _DEFUN(__smakebuf_r, (ptr, fp), |
38 | _DEFUN(__smakebuf_r, (ptr, fp), |
39 | struct _reent *ptr _AND |
39 | struct _reent *ptr _AND |
40 | register FILE *fp) |
40 | register FILE *fp) |
41 | { |
41 | { |
42 | register size_t size, couldbetty; |
- | |
43 | register _PTR p; |
42 | register _PTR p; |
44 | #ifdef __USE_INTERNAL_STAT64 |
- | |
45 | struct stat64 st; |
43 | int flags; |
46 | #else |
44 | size_t size; |
47 | struct stat st; |
45 | int couldbetty; |
48 | #endif |
- | |
Line 49... | Line 46... | ||
49 | 46 | ||
50 | if (fp->_flags & __SNBF) |
47 | if (fp->_flags & __SNBF) |
51 | { |
48 | { |
52 | fp->_bf._base = fp->_p = fp->_nbuf; |
49 | fp->_bf._base = fp->_p = fp->_nbuf; |
53 | fp->_bf._size = 1; |
50 | fp->_bf._size = 1; |
54 | return; |
51 | return; |
55 | } |
- | |
56 | #ifdef __USE_INTERNAL_STAT64 |
52 | } |
57 | if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0) |
- | |
58 | #else |
- | |
59 | if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0) |
- | |
60 | #endif |
- | |
61 | { |
- | |
62 | couldbetty = 0; |
- | |
63 | /* Check if we are be called by asprintf family for initial buffer. */ |
- | |
64 | if (fp->_flags & __SMBF) |
- | |
65 | size = _DEFAULT_ASPRINTF_BUFSIZE; |
- | |
66 | else |
- | |
67 | size = BUFSIZ; |
- | |
68 | #ifdef _FSEEK_OPTIMIZATION |
- | |
69 | /* do not try to optimise fseek() */ |
- | |
70 | fp->_flags |= __SNPT; |
- | |
71 | #endif |
- | |
72 | } |
- | |
73 | else |
- | |
74 | { |
- | |
75 | couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; |
- | |
76 | #ifdef HAVE_BLKSIZE |
- | |
77 | size = st.st_blksize <= 0 ? BUFSIZ : st.st_blksize; |
- | |
78 | #else |
- | |
79 | size = BUFSIZ; |
- | |
80 | #endif |
- | |
81 | #ifdef _FSEEK_OPTIMIZATION |
- | |
82 | /* |
- | |
83 | * Optimize fseek() only if it is a regular file. |
- | |
84 | * (The test for __sseek is mainly paranoia.) |
- | |
85 | */ |
- | |
86 | if ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek) |
- | |
87 | { |
- | |
88 | fp->_flags |= __SOPT; |
- | |
89 | #ifdef HAVE_BLKSIZE |
- | |
90 | fp->_blksize = st.st_blksize; |
- | |
91 | #else |
- | |
92 | fp->_blksize = 1024; |
- | |
93 | #endif |
- | |
94 | } |
- | |
95 | else |
- | |
96 | fp->_flags |= __SNPT; |
- | |
97 | #endif |
- | |
98 | } |
53 | flags = __swhatbuf_r (ptr, fp, &size, &couldbetty); |
99 | if ((p = _malloc_r (ptr, size)) == NULL) |
54 | if ((p = _malloc_r (ptr, size)) == NULL) |
100 | { |
55 | { |
101 | if (!(fp->_flags & __SSTR)) |
56 | if (!(fp->_flags & __SSTR)) |
102 | { |
57 | { |
Line 111... | Line 66... | ||
111 | fp->_flags |= __SMBF; |
66 | fp->_flags |= __SMBF; |
112 | fp->_bf._base = fp->_p = (unsigned char *) p; |
67 | fp->_bf._base = fp->_p = (unsigned char *) p; |
113 | fp->_bf._size = size; |
68 | fp->_bf._size = size; |
114 | if (couldbetty && _isatty_r (ptr, fp->_file)) |
69 | if (couldbetty && _isatty_r (ptr, fp->_file)) |
115 | fp->_flags |= __SLBF; |
70 | fp->_flags |= __SLBF; |
- | 71 | fp->_flags |= flags; |
|
- | 72 | } |
|
116 | } |
73 | } |
- | 74 | ||
- | 75 | /* |
|
- | 76 | * Internal routine to determine `proper' buffering for a file. |
|
- | 77 | */ |
|
- | 78 | int |
|
- | 79 | _DEFUN(__swhatbuf_r, (ptr, fp, bufsize, couldbetty), |
|
- | 80 | struct _reent *ptr _AND |
|
- | 81 | FILE *fp _AND |
|
- | 82 | size_t *bufsize _AND |
|
- | 83 | int *couldbetty) |
|
- | 84 | { |
|
- | 85 | #ifdef _FSEEK_OPTIMIZATION |
|
- | 86 | const int snpt = __SNPT; |
|
- | 87 | #else |
|
- | 88 | const int snpt = 0; |
|
- | 89 | #endif |
|
- | 90 | ||
- | 91 | #ifdef __USE_INTERNAL_STAT64 |
|
- | 92 | struct stat64 st; |
|
- | 93 | ||
- | 94 | if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0) |
|
- | 95 | #else |
|
- | 96 | struct stat st; |
|
- | 97 | ||
- | 98 | if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0) |
|
- | 99 | #endif |
|
- | 100 | { |
|
- | 101 | *couldbetty = 0; |
|
- | 102 | /* Check if we are be called by asprintf family for initial buffer. */ |
|
- | 103 | if (fp->_flags & __SMBF) |
|
- | 104 | *bufsize = _DEFAULT_ASPRINTF_BUFSIZE; |
|
- | 105 | else |
|
- | 106 | *bufsize = BUFSIZ; |
|
- | 107 | return (0); |
|
- | 108 | } |
|
- | 109 | ||
- | 110 | /* could be a tty iff it is a character device */ |
|
- | 111 | *couldbetty = S_ISCHR(st.st_mode); |
|
- | 112 | #ifdef HAVE_BLKSIZE |
|
- | 113 | if (st.st_blksize > 0) |
|
- | 114 | { |
|
- | 115 | /* |
|
- | 116 | * Optimise fseek() only if it is a regular file. (The test for |
|
- | 117 | * __sseek is mainly paranoia.) It is safe to set _blksize |
|
- | 118 | * unconditionally; it will only be used if __SOPT is also set. |
|
- | 119 | */ |
|
- | 120 | *bufsize = st.st_blksize; |
|
- | 121 | fp->_blksize = st.st_blksize; |
|
- | 122 | return ((st.st_mode & S_IFMT) == S_IFREG ? __SOPT : snpt); |
|
- | 123 | } |
|
- | 124 | #endif |
|
- | 125 | *bufsize = BUFSIZ; |
|
- | 126 | return (snpt); |
|
117 | }=>>>>> |
127 | }>>>> |