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>
21 #include "errmap_nt.h"
28 * renamefile() -- rename a file (Unix rename() semantics)
31 renamefile(const char *oldname, const char *newname)
36 if (!MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING)) {
38 errno = nterr_nt2unix(GetLastError(), EIO);
42 rc = rename(oldname, newname);
49 * FilepathNormalizeEx() -- normalize file path; i.e., use only forward (or only
50 * backward) slashes, remove multiple and trailing slashes.
53 FilepathNormalizeEx(char *path, int slashType)
57 char slash = '/'; /* Default to forward slashes */
59 if (slashType == FPN_BACK_SLASHES)
63 /* use only forward slashes; remove multiple slashes */
64 for (pP = pCopyFrom = path; *pCopyFrom != '\0'; pCopyFrom++) {
65 if ((*pCopyFrom == '/') || (*pCopyFrom == '\\')) {
77 /* strip off trailing slash (unless specifies root) */
79 if ((*pP == slash) && (pP != path)) {
82 if (*(pP - 1) != ':') {
94 FilepathNormalize(char *path)
96 FilepathNormalizeEx(path, FPN_FORWARD_SLASHES);
99 /* Open a file for buffered I/O */
101 BufioOpen(char *path, int oflag, int mode)
105 bp = (bufio_p) malloc(sizeof(bufio_t));
110 bp->fd = _open(path, oflag, mode);
112 bp->fd = open(path, oflag, mode);
114 if (bp->fd == BUFIO_INVALID_FD) {
126 /* Read the next line of a file up to len-1 bytes into buf,
127 * and strip off the carriage return. buf is null terminated.
128 * Returns -1 on EOF or error, length of string on success.
131 BufioGets(bufio_p bp, char *buf, int buflen)
137 if (!buf || buflen <= 1 || !bp || bp->eof) {
147 rc = _read(bp->fd, bp->buf, BUFIO_BUFSIZE);
149 rc = read(bp->fd, bp->buf, BUFIO_BUFSIZE);
154 } else if (rc == 0) {
174 if (tlen >= buflen - 1) {
185 /* Close a buffered I/O handle */
187 BufioClose(bufio_p bp)