|
1 /************************************************************************ |
|
2 * |
|
3 * file.h - common file I/O definitions |
|
4 * |
|
5 * $Id: file.h 290020 2005-09-18 23:58:30Z sebor $ |
|
6 * |
|
7 *************************************************************************** |
|
8 * |
|
9 * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave |
|
10 * Software division. Licensed under the Apache License, Version 2.0 (the |
|
11 * "License"); you may not use this file except in compliance with the |
|
12 * License. You may obtain a copy of the License at |
|
13 * http://www.apache.org/licenses/LICENSE-2.0. Unless required by |
|
14 * applicable law or agreed to in writing, software distributed under |
|
15 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
|
16 * CONDITIONS OF ANY KIND, either express or implied. See the License |
|
17 * for the specific language governing permissions and limitations under |
|
18 * the License. |
|
19 * |
|
20 **************************************************************************/ |
|
21 |
|
22 #ifndef RW_FILE_H_INCLUDED |
|
23 #define RW_FILE_H_INCLUDED |
|
24 |
|
25 |
|
26 #include <testdefs.h> // for test config macros |
|
27 |
|
28 |
|
29 #ifndef _MSC_VER |
|
30 // POSIX special files: |
|
31 // http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap10.html |
|
32 # define DEV_CONSOLE "/dev/console" |
|
33 # define DEV_NULL "/dev/null" |
|
34 # define DEV_TTY "/dev/tty" |
|
35 #else // if defined (_MSC_VER) |
|
36 # define DEV_CONSOLE "CON:" |
|
37 # define DEV_NULL "NUL:" |
|
38 # define DEV_TTY "CON:" |
|
39 #endif // _MSC_VER |
|
40 |
|
41 |
|
42 #if _RWSTD_PATH_SEP == '/' |
|
43 # define SLASH "/" |
|
44 # define SHELL_MV "mv " |
|
45 # define SHELL_RM_F "rm -f " |
|
46 # define SHELL_RM_RF "rm -rf " |
|
47 #else |
|
48 # define SLASH "\\" |
|
49 # define SHELL_MV "move /Y " |
|
50 # define SHELL_RM_F "del /F " |
|
51 # define SHELL_RM_RF "rmdir /Q /S " |
|
52 #endif |
|
53 |
|
54 |
|
55 // writes chars using symbolic names from the Portable Character Set (PCS) |
|
56 // or using the <U00XX> notations for narrow characters outside that set |
|
57 // if teh second argument is 0, writes out the CHARMAP section of the locale |
|
58 // definition file for the Portable Character Set (in POSIX-compliant format) |
|
59 _TEST_EXPORT void |
|
60 pcs_write (void*, const char*); |
|
61 |
|
62 |
|
63 // creates a unique temporary file name as if by calling tmpnam() |
|
64 // but avoiding various platform-specific quirks (such as HP-UX |
|
65 // failure when _REENTRANT is #defined or GNU glibc warnings) |
|
66 _TEST_EXPORT |
|
67 const char* rw_tmpnam (char*); |
|
68 |
|
69 // tries to open file named by the first argument and, if successful, |
|
70 // allocates a block of storage sufficiently large to hold the file's |
|
71 // entire contents, as determined by the stat() function; it then reads |
|
72 // the contents of the file into the block of storage, returning a pointer |
|
73 // to the block; if the second argument is non-0, sets the pointed-to value |
|
74 // to the number of bytes read |
|
75 // as a special case, when the first argument is 0 and the second is not, |
|
76 // the function takes the third argument as a pointer to the buffer that |
|
77 // it will use to read the contents of files into in subsequent calls, |
|
78 // provided the buffer is large enough |
|
79 _TEST_EXPORT void* |
|
80 rw_fread (const char*, |
|
81 _RWSTD_SIZE_T* = 0 /* size in bytes */, |
|
82 const char* = "r" /* stdio open mode */); |
|
83 |
|
84 // if the second argument is non-0, writes N bytes starting at that |
|
85 // location into the file named by the first argument; N is taken |
|
86 // from the value pointed to by the third argument, if non-0, or |
|
87 // as the result of calling strlen() on the buffer pointed to by |
|
88 // the second argument; if the second argument is 0, the function |
|
89 // removes the named file; returns the number of bytes written |
|
90 _TEST_EXPORT _RWSTD_SIZE_T |
|
91 rw_fwrite (const char*, |
|
92 const void*, |
|
93 _RWSTD_SIZE_T = ~0 /* size in bytes */, |
|
94 const char* = "w" /* stdio open mode */ ); |
|
95 |
|
96 #endif // RW_FILE_H_INCLUDED |