2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* File-oriented utility functions */
12 #include <afsconfig.h>
13 #include <afs/param.h>
28 #include "errmap_nt.h"
34 #include <sys/types.h>
44 * renamefile() -- rename a file (Unix rename() semantics)
47 renamefile(const char *oldname, const char *newname)
52 if (!MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING)) {
54 errno = nterr_nt2unix(GetLastError(), EIO);
58 rc = rename(oldname, newname);
65 * FilepathNormalizeEx() -- normalize file path; i.e., use only forward (or only
66 * backward) slashes, remove multiple and trailing slashes.
69 FilepathNormalizeEx(char *path, int slashType)
73 char slash = '/'; /* Default to forward slashes */
75 if (slashType == FPN_BACK_SLASHES)
79 /* use only forward slashes; remove multiple slashes */
80 for (pP = pCopyFrom = path; *pCopyFrom != '\0'; pCopyFrom++) {
81 if ((*pCopyFrom == '/') || (*pCopyFrom == '\\')) {
93 /* strip off trailing slash (unless specifies root) */
95 if ((*pP == slash) && (pP != path)) {
98 if (*(pP - 1) != ':') {
110 FilepathNormalize(char *path)
112 FilepathNormalizeEx(path, FPN_FORWARD_SLASHES);
115 /* Open a file for buffered I/O */
117 BufioOpen(char *path, int oflag, int mode)
121 bp = (bufio_p) malloc(sizeof(bufio_t));
126 bp->fd = _open(path, oflag, mode);
128 bp->fd = open(path, oflag, mode);
130 if (bp->fd == BUFIO_INVALID_FD) {
142 /* Read the next line of a file up to len-1 bytes into buf,
143 * and strip off the carriage return. buf is null terminated.
144 * Returns -1 on EOF or error, length of string on success.
147 BufioGets(bufio_p bp, char *buf, int buflen)
153 if (!buf || buflen <= 1 || !bp || bp->eof) {
163 rc = _read(bp->fd, bp->buf, BUFIO_BUFSIZE);
165 rc = read(bp->fd, bp->buf, BUFIO_BUFSIZE);
170 } else if (rc == 0) {
190 if (tlen >= buflen - 1) {
201 /* Close a buffered I/O handle */
203 BufioClose(bufio_p bp)