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"
27 * FilepathNormalizeEx() -- normalize file path; i.e., use only forward (or only
28 * backward) slashes, remove multiple and trailing slashes.
31 FilepathNormalizeEx(char *path
, int slashType
)
35 char slash
= '/'; /* Default to forward slashes */
37 if (slashType
== FPN_BACK_SLASHES
)
41 /* use only forward slashes; remove multiple slashes */
42 for (pP
= pCopyFrom
= path
; *pCopyFrom
!= '\0'; pCopyFrom
++) {
43 if ((*pCopyFrom
== '/') || (*pCopyFrom
== '\\')) {
55 /* strip off trailing slash (unless specifies root) */
57 if ((*pP
== slash
) && (pP
!= path
)) {
60 if (*(pP
- 1) != ':') {
72 FilepathNormalize(char *path
)
74 FilepathNormalizeEx(path
, FPN_FORWARD_SLASHES
);
77 /* Open a file for buffered I/O */
79 BufioOpen(char *path
, int oflag
, int mode
)
83 bp
= malloc(sizeof(bufio_t
));
88 bp
->fd
= _open(path
, oflag
, mode
);
90 bp
->fd
= open(path
, oflag
, mode
);
92 if (bp
->fd
== BUFIO_INVALID_FD
) {
104 /* Read the next line of a file up to len-1 bytes into buf,
105 * and strip off the carriage return. buf is null terminated.
106 * Returns -1 on EOF or error, length of string on success.
109 BufioGets(bufio_p bp
, char *buf
, int buflen
)
115 if (!buf
|| buflen
<= 1 || !bp
|| bp
->eof
) {
125 rc
= _read(bp
->fd
, bp
->buf
, BUFIO_BUFSIZE
);
127 rc
= read(bp
->fd
, bp
->buf
, BUFIO_BUFSIZE
);
132 } else if (rc
== 0) {
152 if (tlen
>= buflen
- 1) {
163 /* Close a buffered I/O handle */
165 BufioClose(bufio_p bp
)