*** empty log message ***
[debian/tar] / src / rmt.h
1 /* Remote tape drive defines for tar.
2    Copyright (C) 1988 Free Software Foundation
3
4 This file is part of GNU Tar.
5
6 GNU Tar is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Tar is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Tar; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #if defined(HAVE_UNISTD_H)
21 #include <unistd.h>
22 #endif /* HAVE_UNISTD_H */
23
24 #if !defined(_POSIX_VERSION)
25 #ifdef __MSDOS__
26 #include <io.h>
27 #else /* !__MSDOS__ */
28 extern off_t lseek();
29 #endif /* __MSDOS__ */
30 #endif /* _POSIX_VERSION */
31
32 #ifdef NO_REMOTE
33 #define _isrmt(f)       0
34 #define rmtopen         open
35 #define rmtaccess       access
36 #define rmtstat         stat
37 #define rmtcreat        creat
38 #define rmtlstat        lstat
39 #define rmtread         read
40 #define rmtwrite        write
41 #define rmtlseek        lseek
42 #define rmtclose        close
43 #define rmtioctl        ioctl
44 #define rmtdup          dup
45 #define rmtfstat        fstat
46 #define rmtfcntl        fcntl
47 #define rmtisatty       isatty
48
49 #else /* !NO_REMOTE */
50
51 #define __REM_BIAS      128
52 #define RMTIOCTL
53
54 #ifndef O_CREAT
55 #define O_CREAT 01000
56 #endif
57
58 extern char *__rmt_path;
59
60 extern long __rmt_lseek();
61
62 #if !defined(USG) && !defined(STDC_HEADERS)
63 #define strchr index
64 #endif
65 extern char *strchr();
66
67 #define _remdev(path)   ((__rmt_path=strchr(path, ':')) && strncmp(__rmt_path, ":/dev/", 6)==0)
68 #define _isrmt(fd)              ((fd) >= __REM_BIAS)
69
70 #define rmtopen(path,oflag,mode) (_remdev(path) ? __rmt_open(path, oflag, mode, __REM_BIAS) : open(path, oflag, mode))
71 #define rmtaccess(path, amode)  (_remdev(path) ? 0 : access(path, amode))
72 #define rmtstat(path, buf)      (_remdev(path) ? (errno = EOPNOTSUPP), -1 : stat(path, buf))
73 #define rmtcreat(path, mode)    (_remdev(path) ? __rmt_open (path, 1 | O_CREAT, mode, __REM_BIAS) : creat(path, mode))
74 #define rmtlstat(path,buf)      (_remdev(path) ? (errno = EOPNOTSUPP), -1 : lstat(path,buf))
75
76 #define rmtread(fd, buf, n)     (_isrmt(fd) ? __rmt_read(fd - __REM_BIAS, buf, n) : read(fd, buf, n))
77 #define rmtwrite(fd, buf, n)    (_isrmt(fd) ? __rmt_write(fd - __REM_BIAS, buf, n) : write(fd, buf, n))
78 #define rmtlseek(fd, off, wh)   (_isrmt(fd) ? __rmt_lseek(fd - __REM_BIAS, off, wh) : lseek(fd, off, wh))
79 #define rmtclose(fd)            (_isrmt(fd) ? __rmt_close(fd - __REM_BIAS) : close(fd))
80 #ifdef RMTIOCTL
81 #define rmtioctl(fd,req,arg)    (_isrmt(fd) ? __rmt_ioctl(fd - __REM_BIAS, req, arg) : ioctl(fd, req, arg))
82 #else
83 #define rmtioctl(fd,req,arg)    (_isrmt(fd) ? (errno = EOPNOTSUPP), -1 : ioctl(fd, req, arg))
84 #endif
85 #define rmtdup(fd)              (_isrmt(fd) ? (errno = EOPNOTSUPP), -1 : dup(fd))
86 #define rmtfstat(fd, buf)       (_isrmt(fd) ? (errno = EOPNOTSUPP), -1 : fstat(fd, buf))
87 #define rmtfcntl(fd,cmd,arg)    (_isrmt(fd) ? (errno = EOPNOTSUPP), -1 : fcntl (fd, cmd, arg))
88 #define rmtisatty(fd)           (_isrmt(fd) ? 0 : isatty(fd))
89
90 #undef RMTIOCTL
91 #endif /* !NO_REMOTE */