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>
27 #include "errmap_nt.h"
40 #include <sys/types.h>
50 * renamefile() -- rename a file (Unix rename() semantics)
53 renamefile(const char *oldname, const char *newname)
58 if (!MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING)) {
60 errno = nterr_nt2unix(GetLastError(), EIO);
64 rc = rename(oldname, newname);
71 * FilepathNormalizeEx() -- normalize file path; i.e., use only forward (or only
72 * backward) slashes, remove multiple and trailing slashes.
75 FilepathNormalizeEx(char *path, int slashType)
79 char slash = '/'; /* Default to forward slashes */
81 if (slashType == FPN_BACK_SLASHES)
85 /* use only forward slashes; remove multiple slashes */
86 for (pP = pCopyFrom = path; *pCopyFrom != '\0'; pCopyFrom++) {
87 if ((*pCopyFrom == '/') || (*pCopyFrom == '\\')) {
99 /* strip off trailing slash (unless specifies root) */
101 if ((*pP == slash) && (pP != path)) {
103 /* check for "X:/" */
104 if (*(pP - 1) != ':') {
116 FilepathNormalize(char *path)
118 FilepathNormalizeEx(path, FPN_FORWARD_SLASHES);
121 /* Open a file for buffered I/O */
123 BufioOpen(char *path, int oflag, int mode)
127 bp = (bufio_p) malloc(sizeof(bufio_t));
132 bp->fd = _open(path, oflag, mode);
134 bp->fd = open(path, oflag, mode);
136 if (bp->fd == BUFIO_INVALID_FD) {
148 /* Read the next line of a file up to len-1 bytes into buf,
149 * and strip off the carriage return. buf is null terminated.
150 * Returns -1 on EOF or error, length of string on success.
153 BufioGets(bufio_p bp, char *buf, int buflen)
159 if (!buf || buflen <= 1 || !bp || bp->eof) {
169 rc = _read(bp->fd, bp->buf, BUFIO_BUFSIZE);
171 rc = read(bp->fd, bp->buf, BUFIO_BUFSIZE);
176 } else if (rc == 0) {
196 if (tlen >= buflen - 1) {
207 /* Close a buffered I/O handle */
209 BufioClose(bufio_p bp)