2 ** Copyright 2000 Double Precision, Inc.
3 ** See COPYING for distribution information.
10 #include <sys/types.h>
23 #include "maildirmisc.h"
26 char *maildir_getlink(const char *filename)
41 if ((buf=malloc(bufsiz)) == 0)
46 if ((n=readlink(filename, buf, bufsiz)) < 0)
63 int maildir_semisafeopen(const char *path, int mode, int perm)
68 char *l=maildir_getlink(path);
76 char *q=malloc(strlen(path)+strlen(l)+2);
86 if ((s=strchr(q, '/')) != 0)
94 f=maildir_safeopen(l, mode, perm);
101 return (maildir_safeopen(path, mode, perm));
104 int maildir_safeopen(const char *path, int mode, int perm)
108 return maildir_safeopen_stat(path, mode, perm, &stat1);
111 int maildir_safeopen_stat(const char *path, int mode, int perm,
116 int fd=open(path, mode
124 if (fd < 0) return (fd);
125 if (fcntl(fd, F_SETFL, (mode & O_APPEND)) || fstat(fd, stat1)
126 || lstat(path, &stat2))
132 if (stat1->st_dev != stat2.st_dev || stat1->st_ino != stat2.st_ino)