version 1.13, 2001/09/03 15:53:00 |
version 1.14, 2001/09/03 16:15:08 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/uio.h> |
#include <sys/uio.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
#include <sys/file.h> |
|
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
|
#include <fcntl.h> |
#include <locale.h> |
#include <locale.h> |
#include <pwd.h> |
#include <pwd.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
}; |
}; |
|
|
|
|
int openf(char *path); |
|
|
|
void |
void |
cal() |
cal() |
{ |
{ |
|
|
return (val); |
return (val); |
} |
} |
|
|
char path[MAXPATHLEN]; |
|
|
|
int |
|
openf(path) |
|
char *path; |
|
{ |
|
struct stat st; |
|
int fd; |
|
|
|
fd = open(path, O_RDONLY|O_NONBLOCK); |
|
if (fd == -1) |
|
return (-1); |
|
if (fstat(fd, &st) == -1) { |
|
close(fd); |
|
return (-1); |
|
} |
|
if ((st.st_mode & S_IFMT) != S_IFREG) { |
|
close (fd); |
|
return (-1); |
|
} |
|
|
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) &~ O_NONBLOCK); |
|
return (fd); |
|
} |
|
|
|
FILE * |
FILE * |
opencal() |
opencal() |
{ |
{ |
|
|
int fdin; |
int fdin; |
|
|
/* open up calendar file as stdin */ |
/* open up calendar file as stdin */ |
if ((fdin = openf(calendarFile)) == -1) { |
if ((fdin = open(calendarFile, O_RDONLY)) == -1) { |
if (!doall) { |
if (!doall) { |
char *home = getenv("HOME"); |
char *home = getenv("HOME"); |
if (home == NULL || *home == '\0') |
if (home == NULL || *home == '\0') |
errx(1, "cannot get home directory"); |
errx(1, "cannot get home directory"); |
if (!(chdir(home) == 0 && |
if (!(chdir(home) == 0 && |
chdir(calendarHome) == 0 && |
chdir(calendarHome) == 0 && |
(fdin = openf(calendarFile)) != -1)) |
(fdin = open(calendarFile, O_RDONLY)) != -1)) |
errx(1, "no calendar file: ``%s'' or ``~/%s/%s", |
errx(1, "no calendar file: ``%s'' or ``~/%s/%s", |
calendarFile, calendarHome, calendarFile); |
calendarFile, calendarHome, calendarFile); |
} |
} |