-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfname.h
116 lines (87 loc) · 2.85 KB
/
fname.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* This file is part of the auxiliaries library.
Written by Dick Grune, Vrije Universiteit, Amsterdam.
$Id: fname.h,v 1.8 2012-06-13 09:59:52 Gebruiker Exp $
*/
/* Support for UNICODE file names */
/*
To accommodate UNICODE file names on various platforms, this file defines
the types
Fchar file name character
Dir_t struct for accessing a directory
Dirent_t struct for accessing a directory entry
and the functions
Dir_t* Opendir(const Fchar*);
Dirent_t* Readdir(Dir_t*);
int Closedir(Dir_t*);
Fchar *Fnamecpy(Fchar *dest, Fchar *source);
Fchar *Fnamecat(Fchar*, const Fchar*);
size_t Fnamelen(const Fchar*);
int Fnamecmp(const Fchar*, const Fchar*);
int Stat(const Fchar *fn, struct stat *st);
FILE *Fopen(const Fchar *fn, const char *rb);
The stream is still char*!
int Fclose(FILE*);
const char *Fname2str(const Fchar *fn);
const Fchar *str2Fname(const char *s);
The result of these two routines is transient: is is good only until
the next call.
The only way to obtain a file name is through readdir; the command line
arguments are in ASCII. So a program can be adapted by replacing
DIR by Dir_t, and
struct dirent by Dirent_t.
Compiling and correcting using the above replacements until there are no
more errors or warnings will then yield an UTF-16 compatible program.
For details about UTF-16 see fname.c.
*/
#ifndef _FNAME_H_
#define _FNAME_H_
/* lint cannot handle the weird code Windows throws at it, so even under
Windows we clain to have UTF8
*/
#ifdef MSDOS
#define IS_UTF_16
#endif
#ifdef lint
#undef IS_UTF_16
#endif
#ifdef IS_UTF_16 /* file names in UTF-16 */
#define _UNICODE
#include <tchar.h>
#include <sys/stat.h>
#include <dirent.h>
typedef _TCHAR Fchar;
typedef _WDIR Dir_t;
typedef struct _tdirent Dirent_t;
#define Opendir _topendir
#define Closedir _tclosedir
#define Readdir _treaddir
#define Fnamecpy wcscpy
#define Fnamecat wcscat
#define Fnamelen wcslen
#define Fnamecmp wcscmp
extern const char *Fname2str(const Fchar *fn); /* transient! */
extern const Fchar *str2Fname(const char *s); /* transient! */
extern int Stat(const Fchar *fn, struct stat *st);
extern FILE *Fopen(const Fchar *fn, const char *rb);/* stream is still char* */
#define Fclose fclose
#else /* not MSDOS */ /* file names are in UTF-8 */
#include <sys/stat.h>
#include <dirent.h>
/* life is simple */
typedef char Fchar;
#define Fnamecpy strcpy
#define Fnamecat strcat
#define Fnamelen strlen
#define Fnamecmp strcmp
#define Fname2str(fn) (fn)
#define str2Fname(s) (s)
#define Stat(fn,st) stat(fn,st)
typedef DIR Dir_t;
typedef struct dirent Dirent_t;
#define Opendir opendir
#define Closedir closedir
#define Readdir readdir
#define Fopen fopen
#define Fclose fclose
#endif /* MSDOS */
#endif /* _FNAME_H_ */