version 1.1.1.3, 2011/09/16 17:47:07 |
version 1.1.1.4, 2014/04/25 13:33:49 |
|
|
/* |
/* |
* Copyright (C) 1984-2011 Mark Nudelman |
* Copyright (C) 1984-2012 Mark Nudelman |
* |
* |
* You may distribute under the terms of either the GNU General Public |
* You may distribute under the terms of either the GNU General Public |
* License or the Less License, as specified in the README file. |
* License or the Less License, as specified in the README file. |
* |
* |
* For more information about less, or for information on how to |
* For more information, see the README file. |
* contact the author, see the README file. |
|
*/ |
*/ |
|
|
|
|
|
|
|
|
#include "less.h" |
#include "less.h" |
#include <signal.h> |
#include <signal.h> |
#include <setjmp.h> |
|
#if HAVE_TIME_H |
#if HAVE_TIME_H |
#include <time.h> |
#include <time.h> |
#endif |
#endif |
|
|
#define time_type long |
#define time_type long |
#endif |
#endif |
|
|
/* |
extern volatile sig_atomic_t sigs; |
* BSD setjmp() saves (and longjmp() restores) the signal mask. |
|
* This costs a system call or two per setjmp(), so if possible we clear the |
|
* signal mask with sigsetmask(), and use _setjmp()/_longjmp() instead. |
|
* On other systems, setjmp() doesn't affect the signal mask and so |
|
* _setjmp() does not exist; we just use setjmp(). |
|
*/ |
|
#if HAVE__SETJMP && HAVE_SIGSETMASK |
|
#define SET_JUMP _setjmp |
|
#define LONG_JUMP _longjmp |
|
#else |
|
#define SET_JUMP setjmp |
|
#define LONG_JUMP longjmp |
|
#endif |
|
|
|
public int reading; |
|
|
|
static jmp_buf read_label; |
|
|
|
extern int sigs; |
|
|
|
/* |
/* |
* Like read() system call, but is deliberately interruptible. |
* Like read() system call, but is deliberately interruptible. |
* A call to intread() from a signal handler will interrupt |
|
* any pending iread(). |
|
*/ |
*/ |
public int |
public int |
iread(fd, buf, len) |
iread(fd, buf, len) |
|
|
} |
} |
#endif |
#endif |
#endif |
#endif |
if (SET_JUMP(read_label)) |
|
{ |
|
/* |
|
* We jumped here from intread. |
|
*/ |
|
reading = 0; |
|
#if HAVE_SIGPROCMASK |
|
{ |
|
sigset_t mask; |
|
sigemptyset(&mask); |
|
sigprocmask(SIG_SETMASK, &mask, NULL); |
|
} |
|
#else |
|
#if HAVE_SIGSETMASK |
|
sigsetmask(0); |
|
#else |
|
#ifdef _OSK |
|
sigmask(~0); |
|
#endif |
|
#endif |
|
#endif |
|
return (READ_INTR); |
|
} |
|
|
|
flush(); |
flush(); |
reading = 1; |
|
#if MSDOS_COMPILER==DJGPPC |
#if MSDOS_COMPILER==DJGPPC |
if (isatty(fd)) |
if (isatty(fd)) |
{ |
{ |
|
|
} |
} |
} |
} |
#endif |
#endif |
reading = 0; |
|
if (n < 0) |
if (n < 0) |
{ |
{ |
#if HAVE_ERRNO |
#if HAVE_ERRNO |
|
|
#endif |
#endif |
#ifdef EINTR |
#ifdef EINTR |
if (errno == EINTR) |
if (errno == EINTR) |
goto start; |
return (READ_INTR); |
#endif |
#endif |
#ifdef EAGAIN |
#ifdef EAGAIN |
if (errno == EAGAIN) |
if (errno == EAGAIN) |
|
|
} |
} |
|
|
/* |
/* |
* Interrupt a pending iread(). |
|
*/ |
|
public void |
|
intread() |
|
{ |
|
LONG_JUMP(read_label, 1); |
|
} |
|
|
|
/* |
|
* Return the current time. |
* Return the current time. |
*/ |
*/ |
#if HAVE_TIME |
#if HAVE_TIME |
|
|
|
|
if (err < sys_nerr) |
if (err < sys_nerr) |
return sys_errlist[err]; |
return sys_errlist[err]; |
sprintf(buf, "Error %d", err); |
snprintf(buf, sizeof(buf), "Error %d", err); |
return buf; |
return buf; |
#else |
#else |
return ("cannot open"); |
return ("cannot open"); |
|
|
{ |
{ |
register char *p; |
register char *p; |
register char *m; |
register char *m; |
int len; |
size_t len; |
#if HAVE_ERRNO |
#if HAVE_ERRNO |
#if MUST_DEFINE_ERRNO |
#if MUST_DEFINE_ERRNO |
extern int errno; |
extern int errno; |