os.c (161475) | os.c (170256) |
---|---|
1/* | 1/* |
2 * Copyright (C) 1984-2005 Mark Nudelman | 2 * Copyright (C) 1984-2007 Mark Nudelman |
3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. 9 */ 10 --- 58 unchanged lines hidden (view full) --- 69 public int 70iread(fd, buf, len) 71 int fd; 72 char *buf; 73 unsigned int len; 74{ 75 register int n; 76 | 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. 9 */ 10 --- 58 unchanged lines hidden (view full) --- 69 public int 70iread(fd, buf, len) 71 int fd; 72 char *buf; 73 unsigned int len; 74{ 75 register int n; 76 |
77start: |
|
77#if MSDOS_COMPILER==WIN32C 78 if (ABORT_SIGS()) 79 return (READ_INTR); 80#else 81#if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC 82 if (kbhit()) 83 { 84 int c; --- 66 unchanged lines hidden (view full) --- 151 consecutive_nulls = 0; 152 if (consecutive_nulls > 20) 153 quit(QUIT_ERROR); 154 } 155 } 156#endif 157 reading = 0; 158 if (n < 0) | 78#if MSDOS_COMPILER==WIN32C 79 if (ABORT_SIGS()) 80 return (READ_INTR); 81#else 82#if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC 83 if (kbhit()) 84 { 85 int c; --- 66 unchanged lines hidden (view full) --- 152 consecutive_nulls = 0; 153 if (consecutive_nulls > 20) 154 quit(QUIT_ERROR); 155 } 156 } 157#endif 158 reading = 0; 159 if (n < 0) |
160 { 161#if HAVE_ERRNO 162 /* 163 * Certain values of errno indicate we should just retry the read. 164 */ 165#if MUST_DEFINE_ERRNO 166 extern int errno; 167#endif 168#ifdef EINTR 169 if (errno == EINTR) 170 goto start; 171#endif 172#ifdef EAGAIN 173 if (errno == EAGAIN) 174 goto start; 175#endif 176#endif |
|
159 return (-1); | 177 return (-1); |
178 } |
|
160 return (n); 161} 162 163/* 164 * Interrupt a pending iread(). 165 */ 166 public void 167intread() --- 78 unchanged lines hidden (view full) --- 246 else 247 return (num / (den / 100)); 248} 249 250/* 251 * Return the specified percentage of a POSITION. 252 */ 253 public POSITION | 179 return (n); 180} 181 182/* 183 * Interrupt a pending iread(). 184 */ 185 public void 186intread() --- 78 unchanged lines hidden (view full) --- 265 else 266 return (num / (den / 100)); 267} 268 269/* 270 * Return the specified percentage of a POSITION. 271 */ 272 public POSITION |
254percent_pos(pos, percent) | 273percent_pos(pos, percent, fraction) |
255 POSITION pos; 256 int percent; | 274 POSITION pos; 275 int percent; |
276 long fraction; |
|
257{ | 277{ |
258 POSITION result100; | 278 /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */ 279 long perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100); 280 POSITION temp; |
259 | 281 |
260 if (percent == 0) | 282 if (perden == 0) |
261 return (0); | 283 return (0); |
262 else if ((result100 = pos * percent) / percent == pos) 263 return (result100 / 100); | 284 temp = pos * perden; /* This might overflow. */ 285 if (temp / perden == pos) 286 /* No overflow */ 287 return (temp / NUM_FRAC_DENOM); |
264 else | 288 else |
265 return (percent * (pos / 100)); | 289 /* Above calculation overflows; 290 * use a method that is less precise but won't overflow. */ 291 return (perden * (pos / NUM_FRAC_DENOM)); |
266} 267 268#if !HAVE_STRCHR 269/* 270 * strchr is used by regexp.c. 271 */ 272 char * 273strchr(s, c) --- 56 unchanged lines hidden --- | 292} 293 294#if !HAVE_STRCHR 295/* 296 * strchr is used by regexp.c. 297 */ 298 char * 299strchr(s, c) --- 56 unchanged lines hidden --- |