int link(const char *path1, const char *path2)
{
#define LINK_BUFSIZE 4096
char buf[LINK_BUFSIZE];
int errsave, fd_path1, fd_path2, result, readlen, writelen;
struct stat st_path1;
/* Open the original file. */
if ((fd_path1 = open(path1,O_RDONLY)) < 0) return fd_path1;
/* Obtain the size and the mode. */
if ((result = fstat(fd_path1, &st_path1)) < 0)
{
errsave = errno;
close(fd_path1);
errno = errsave;
return result;
}
/* Create the duplicate copy. */
if ((fd_path2 = open(path2,O_CREAT|O_EXCL|O_WRONLY,st_path1.st_mode)) < 0)
{
errsave = errno;
close(fd_path1);
errno = errsave;
return fd_path2;
}
/* Copy all of the bytes LINK_BUFSIZE at a time. */
while ((readlen = read(fd_path1, &buf, LINK_BUFSIZE)) > 0)
if ((writelen = write(fd_path2, &buf, readlen)) < 0) break;
/* Any trouble reading? */
if (readlen < 0)
{
errsave = errno;
close(fd_path1);
close(fd_path2);
errno = errsave;
return readlen;
}
/* Any trouble writing? */
if (writelen < 0)
{
errsave = errno;
close(fd_path1);
close(fd_path2);
errno = errsave;
return writelen;
}
/* Close the input file. */
if ((result = close(fd_path1)) < 0)
{
errsave = errno;
close(fd_path2);
errno = errsave;
return result;
}
/* Close the output file. */
if ((result = close(fd_path2)) < 0) return result;
/* Success. */
return 0;
}
If link() is being used to rename a file (ie. link(old,new); unlink(old)),
just do a rename(old,new) instead.
- adjtime()
- bcmp(), bcopy(), and bzero(); Workaround:
# define bcopy(src, dst, len) (memmove((dst), (src), (len)))
# define bzero(dst, len) (memset((dst), '\0', (len)))
# define bcmp(src, dst, len) (memcmp((src), (dst), (len)))
Actually, there are versions of bzero() and friends that exist in the NL.
They are used by certain portions of the kernel. If one forgets to include
the macros and an instruction memory protection happens, it is usually
because the code is binding to bzero() in the NL. Note that with the header
files that were contributed for 6.0, there are macros predefined for bzero()
and friends.
- chroot(); no workaround possible; only HP can implement this vital
security functionality
- daemon()
- endgrent()
- endpwent(); but see libBSD from jazz
- fsync(); Workaround:
int fsync(fd)
int fd;
{
extern FCONTROL(short, short, void *);
FCONTROL(_MPE_FILENO(fd), 2, NULL);
return 0;
}
- ftruncate(); Workaround:
int ftruncate(int fd, size_t wantsize)
{
extern FCONTROL(short, short, void *);
long cursize;
/* determine current file size */
if ((cursize = lseek(fd, 0L, 2)) == -1)
return (-1);
/* maybe lengthen... */
if (cursize < wantsize) {
if (lseek(fd, wantsize - 1, 0) == -1 || write(fd, "", 1) == -1) {
return (-1);
}
return (0);
}
/* maybe shorten... */
if (wantsize < cursize) {
if (lseek(fd, wantsize - 1, 0) == -1) {
return (-1);
}
FCONTROL(_MPE_FILENO(fd),6,0); /* Write smaller EOF */
return (0);
}
return (0);
}
- _getch(); use getchar() instead
- getpass(); but see libBSD
- getpwent(); but see libBSD
- getgrent()
- gettimeofday(); but see libBSD
- getusershell(); use the constants '/SYS/HPBIN/SH' or '/SYS/PUB/CI' instead
- initgroups(); not available under MPE because of limited group support
- killpg(); not available under MPE because of limited group support
- major() and minor(); Workaround:
#define major(x) 0
#define minor(x) 0
- mkstemp()
- nice(); but this is coming with 6.0
- readv(); loop doing read() instead
- setgrent()
- setgroups(); not available under MPE because of limited group support
- setitimer()
- setpwent(); but see libBSD
- setsid()
- settimeofday()
- statfs()
- strcasecmp()
- strdup(); but see libBSD
- strncasecmp()
- strsep()
- utimes()
- vfork(); use fork() instead
- writev(); loop doing write() instead