Home | History | Annotate | Line # | Download | only in test
      1      1.1  christos /* Copyright libuv project contributors. All rights reserved.
      2      1.1  christos  *
      3      1.1  christos  * Permission is hereby granted, free of charge, to any person obtaining a copy
      4      1.1  christos  * of this software and associated documentation files (the "Software"), to
      5      1.1  christos  * deal in the Software without restriction, including without limitation the
      6      1.1  christos  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
      7      1.1  christos  * sell copies of the Software, and to permit persons to whom the Software is
      8      1.1  christos  * furnished to do so, subject to the following conditions:
      9      1.1  christos  *
     10      1.1  christos  * The above copyright notice and this permission notice shall be included in
     11      1.1  christos  * all copies or substantial portions of the Software.
     12      1.1  christos  *
     13      1.1  christos  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     14      1.1  christos  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     15      1.1  christos  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     16      1.1  christos  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     17      1.1  christos  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     18      1.1  christos  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     19      1.1  christos  * IN THE SOFTWARE.
     20      1.1  christos  */
     21      1.1  christos 
     22      1.1  christos #ifdef _WIN32
     23      1.1  christos 
     24      1.1  christos #include "uv.h"
     25      1.1  christos #include "task.h"
     26      1.1  christos 
     27      1.1  christos #if defined(__unix__) || defined(__POSIX__) || \
     28      1.1  christos     defined(__APPLE__) || defined(__sun) || \
     29      1.1  christos     defined(_AIX) || defined(__MVS__) || \
     30      1.1  christos     defined(__HAIKU__)
     31      1.1  christos # include <unistd.h> /* unlink, rmdir */
     32      1.1  christos #else
     33      1.1  christos # include <direct.h>
     34      1.1  christos # define rmdir _rmdir
     35      1.1  christos # define unlink _unlink
     36      1.1  christos #endif
     37      1.1  christos 
     38      1.1  christos static int flags;
     39      1.1  christos 
     40      1.1  christos static uv_fs_t close_req;
     41      1.1  christos static uv_fs_t mkdir_req;
     42      1.1  christos static uv_fs_t open_req;
     43      1.1  christos static uv_fs_t read_req;
     44      1.1  christos static uv_fs_t rmdir_req;
     45      1.1  christos static uv_fs_t unlink_req;
     46      1.1  christos static uv_fs_t write_req;
     47      1.1  christos 
     48      1.1  christos static char buf[32];
     49      1.1  christos static uv_buf_t iov;
     50      1.1  christos 
     51      1.1  christos /* Opening the same file multiple times quickly can cause uv_fs_open to fail
     52      1.1  christos  * with EBUSY, so append an identifier to the file name for each operation */
     53      1.1  christos static int sid = 0;
     54      1.1  christos 
     55      1.1  christos #define FILE_NAME_SIZE 128
     56      1.1  christos static char absent_file[FILE_NAME_SIZE];
     57      1.1  christos static char empty_file[FILE_NAME_SIZE];
     58      1.1  christos static char dummy_file[FILE_NAME_SIZE];
     59      1.1  christos static char empty_dir[] = "empty_dir";
     60      1.1  christos 
     61  1.1.1.2  christos static void setup(void) {
     62      1.1  christos   int r;
     63      1.1  christos 
     64      1.1  christos   /* empty_dir */
     65      1.1  christos   r = uv_fs_rmdir(NULL, &rmdir_req, empty_dir, NULL);
     66      1.1  christos   ASSERT(r == 0 || r == UV_ENOENT);
     67      1.1  christos   ASSERT(rmdir_req.result == 0 || rmdir_req.result == UV_ENOENT);
     68      1.1  christos   uv_fs_req_cleanup(&rmdir_req);
     69      1.1  christos 
     70      1.1  christos   r = uv_fs_mkdir(NULL, &mkdir_req, empty_dir, 0755, NULL);
     71  1.1.1.3  christos   ASSERT_OK(r);
     72  1.1.1.3  christos   ASSERT_OK(mkdir_req.result);
     73      1.1  christos   uv_fs_req_cleanup(&mkdir_req);
     74      1.1  christos }
     75      1.1  christos 
     76  1.1.1.2  christos static void refresh(void) {
     77      1.1  christos   int r;
     78      1.1  christos 
     79      1.1  christos   /* absent_file */
     80      1.1  christos   sprintf(absent_file, "test_file_%d", sid++);
     81      1.1  christos 
     82      1.1  christos   r = uv_fs_unlink(NULL, &unlink_req, absent_file, NULL);
     83      1.1  christos   ASSERT(r == 0 || r == UV_ENOENT);
     84      1.1  christos   ASSERT(unlink_req.result == 0 || unlink_req.result == UV_ENOENT);
     85      1.1  christos   uv_fs_req_cleanup(&unlink_req);
     86      1.1  christos 
     87      1.1  christos   /* empty_file */
     88      1.1  christos   sprintf(empty_file, "test_file_%d", sid++);
     89      1.1  christos 
     90      1.1  christos   r = uv_fs_open(NULL, &open_req, empty_file,
     91      1.1  christos     UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL);
     92  1.1.1.3  christos   ASSERT_GE(r, 0);
     93  1.1.1.3  christos   ASSERT_GE(open_req.result, 0);
     94      1.1  christos   uv_fs_req_cleanup(&open_req);
     95      1.1  christos 
     96      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
     97  1.1.1.3  christos   ASSERT_OK(r);
     98  1.1.1.3  christos   ASSERT_OK(close_req.result);
     99      1.1  christos   uv_fs_req_cleanup(&close_req);
    100      1.1  christos 
    101      1.1  christos   /* dummy_file */
    102      1.1  christos   sprintf(dummy_file, "test_file_%d", sid++);
    103      1.1  christos 
    104      1.1  christos   r = uv_fs_open(NULL, &open_req, dummy_file,
    105      1.1  christos     UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL);
    106  1.1.1.3  christos   ASSERT_GE(r, 0);
    107  1.1.1.3  christos   ASSERT_GE(open_req.result, 0);
    108      1.1  christos   uv_fs_req_cleanup(&open_req);
    109      1.1  christos 
    110      1.1  christos   iov = uv_buf_init("a", 1);
    111      1.1  christos   r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
    112  1.1.1.3  christos   ASSERT_EQ(1, r);
    113  1.1.1.3  christos   ASSERT_EQ(1, write_req.result);
    114      1.1  christos   uv_fs_req_cleanup(&write_req);
    115      1.1  christos 
    116      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
    117  1.1.1.3  christos   ASSERT_OK(r);
    118  1.1.1.3  christos   ASSERT_OK(close_req.result);
    119      1.1  christos   uv_fs_req_cleanup(&close_req);
    120      1.1  christos }
    121      1.1  christos 
    122  1.1.1.2  christos static void cleanup(void) {
    123      1.1  christos   unlink(absent_file);
    124      1.1  christos   unlink(empty_file);
    125      1.1  christos   unlink(dummy_file);
    126      1.1  christos }
    127      1.1  christos 
    128      1.1  christos static void openFail(char *file, int error) {
    129      1.1  christos   int r;
    130      1.1  christos 
    131      1.1  christos   refresh();
    132      1.1  christos 
    133      1.1  christos   r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
    134  1.1.1.3  christos   ASSERT_EQ(r, error);
    135  1.1.1.3  christos   ASSERT_EQ(open_req.result, error);
    136      1.1  christos   uv_fs_req_cleanup(&open_req);
    137      1.1  christos 
    138      1.1  christos   /* Ensure the first call does not create the file */
    139      1.1  christos   r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
    140  1.1.1.3  christos   ASSERT_EQ(r, error);
    141  1.1.1.3  christos   ASSERT_EQ(open_req.result, error);
    142      1.1  christos   uv_fs_req_cleanup(&open_req);
    143      1.1  christos 
    144      1.1  christos   cleanup();
    145      1.1  christos }
    146      1.1  christos 
    147      1.1  christos static void refreshOpen(char *file) {
    148      1.1  christos   int r;
    149      1.1  christos 
    150      1.1  christos   refresh();
    151      1.1  christos 
    152      1.1  christos   r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
    153  1.1.1.3  christos   ASSERT_GE(r, 0);
    154  1.1.1.3  christos   ASSERT_GE(open_req.result, 0);
    155      1.1  christos   uv_fs_req_cleanup(&open_req);
    156      1.1  christos }
    157      1.1  christos 
    158      1.1  christos static void writeExpect(char *file, char *expected, int size) {
    159      1.1  christos   int r;
    160      1.1  christos 
    161      1.1  christos   refreshOpen(file);
    162      1.1  christos 
    163      1.1  christos   iov = uv_buf_init("b", 1);
    164      1.1  christos   r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
    165  1.1.1.3  christos   ASSERT_EQ(1, r);
    166  1.1.1.3  christos   ASSERT_EQ(1, write_req.result);
    167      1.1  christos   uv_fs_req_cleanup(&write_req);
    168      1.1  christos 
    169      1.1  christos   iov = uv_buf_init("c", 1);
    170      1.1  christos   r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
    171  1.1.1.3  christos   ASSERT_EQ(1, r);
    172  1.1.1.3  christos   ASSERT_EQ(1, write_req.result);
    173      1.1  christos   uv_fs_req_cleanup(&write_req);
    174      1.1  christos 
    175      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
    176  1.1.1.3  christos   ASSERT_OK(r);
    177  1.1.1.3  christos   ASSERT_OK(close_req.result);
    178      1.1  christos   uv_fs_req_cleanup(&close_req);
    179      1.1  christos 
    180      1.1  christos   /* Check contents */
    181      1.1  christos   r = uv_fs_open(NULL, &open_req, file, UV_FS_O_RDONLY, S_IWUSR | S_IRUSR, NULL);
    182  1.1.1.3  christos   ASSERT_GE(r, 0);
    183  1.1.1.3  christos   ASSERT_GE(open_req.result, 0);
    184      1.1  christos   uv_fs_req_cleanup(&open_req);
    185      1.1  christos 
    186      1.1  christos   iov = uv_buf_init(buf, sizeof(buf));
    187      1.1  christos   r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
    188  1.1.1.3  christos   ASSERT_EQ(r, size);
    189  1.1.1.3  christos   ASSERT_EQ(read_req.result, size);
    190  1.1.1.3  christos   ASSERT_OK(strncmp(buf, expected, size));
    191      1.1  christos   uv_fs_req_cleanup(&read_req);
    192      1.1  christos 
    193      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
    194  1.1.1.3  christos   ASSERT_OK(r);
    195  1.1.1.3  christos   ASSERT_OK(close_req.result);
    196      1.1  christos   uv_fs_req_cleanup(&close_req);
    197      1.1  christos 
    198      1.1  christos   cleanup();
    199      1.1  christos }
    200      1.1  christos 
    201      1.1  christos static void writeFail(char *file, int error) {
    202      1.1  christos   int r;
    203      1.1  christos 
    204      1.1  christos   refreshOpen(file);
    205      1.1  christos 
    206      1.1  christos   iov = uv_buf_init("z", 1);
    207      1.1  christos   r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
    208  1.1.1.3  christos   ASSERT_EQ(r, error);
    209  1.1.1.3  christos   ASSERT_EQ(write_req.result, error);
    210      1.1  christos   uv_fs_req_cleanup(&write_req);
    211      1.1  christos 
    212      1.1  christos   iov = uv_buf_init("z", 1);
    213      1.1  christos   r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
    214  1.1.1.3  christos   ASSERT_EQ(r, error);
    215  1.1.1.3  christos   ASSERT_EQ(write_req.result, error);
    216      1.1  christos   uv_fs_req_cleanup(&write_req);
    217      1.1  christos 
    218      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
    219  1.1.1.3  christos   ASSERT_OK(r);
    220  1.1.1.3  christos   ASSERT_OK(close_req.result);
    221      1.1  christos   uv_fs_req_cleanup(&close_req);
    222      1.1  christos 
    223      1.1  christos   cleanup();
    224      1.1  christos }
    225      1.1  christos 
    226      1.1  christos static void readExpect(char *file, char *expected, int size) {
    227      1.1  christos   int r;
    228      1.1  christos 
    229      1.1  christos   refreshOpen(file);
    230      1.1  christos 
    231      1.1  christos   iov = uv_buf_init(buf, sizeof(buf));
    232      1.1  christos   r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
    233  1.1.1.3  christos   ASSERT_EQ(r, size);
    234  1.1.1.3  christos   ASSERT_EQ(read_req.result, size);
    235  1.1.1.3  christos   ASSERT_OK(strncmp(buf, expected, size));
    236      1.1  christos   uv_fs_req_cleanup(&read_req);
    237      1.1  christos 
    238      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
    239  1.1.1.3  christos   ASSERT_OK(r);
    240  1.1.1.3  christos   ASSERT_OK(close_req.result);
    241      1.1  christos   uv_fs_req_cleanup(&close_req);
    242      1.1  christos 
    243      1.1  christos   cleanup();
    244      1.1  christos }
    245      1.1  christos 
    246      1.1  christos static void readFail(char *file, int error) {
    247      1.1  christos   int r;
    248      1.1  christos 
    249      1.1  christos   refreshOpen(file);
    250      1.1  christos 
    251      1.1  christos   iov = uv_buf_init(buf, sizeof(buf));
    252      1.1  christos   r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
    253  1.1.1.3  christos   ASSERT_EQ(r, error);
    254  1.1.1.3  christos   ASSERT_EQ(read_req.result, error);
    255      1.1  christos   uv_fs_req_cleanup(&read_req);
    256      1.1  christos 
    257      1.1  christos   iov = uv_buf_init(buf, sizeof(buf));
    258      1.1  christos   r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
    259  1.1.1.3  christos   ASSERT_EQ(r, error);
    260  1.1.1.3  christos   ASSERT_EQ(read_req.result, error);
    261      1.1  christos   uv_fs_req_cleanup(&read_req);
    262      1.1  christos 
    263      1.1  christos   r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
    264  1.1.1.3  christos   ASSERT_OK(r);
    265  1.1.1.3  christos   ASSERT_OK(close_req.result);
    266      1.1  christos   uv_fs_req_cleanup(&close_req);
    267      1.1  christos 
    268      1.1  christos   cleanup();
    269      1.1  christos }
    270      1.1  christos 
    271      1.1  christos static void fs_open_flags(int add_flags) {
    272      1.1  christos   /* Follow the order from
    273      1.1  christos    * https://github.com/nodejs/node/blob/1a96abe849/lib/internal/fs/utils.js#L329-L354
    274      1.1  christos    */
    275      1.1  christos 
    276      1.1  christos   /* r */
    277      1.1  christos   flags = add_flags | UV_FS_O_RDONLY;
    278      1.1  christos   openFail(absent_file, UV_ENOENT);
    279  1.1.1.2  christos   writeFail(empty_file, UV_EBADF);
    280      1.1  christos   readExpect(empty_file, "", 0);
    281  1.1.1.2  christos   writeFail(dummy_file, UV_EBADF);
    282      1.1  christos   readExpect(dummy_file, "a", 1);
    283  1.1.1.2  christos   writeFail(empty_dir, UV_EBADF);
    284      1.1  christos   readFail(empty_dir, UV_EISDIR);
    285      1.1  christos 
    286      1.1  christos   /* rs */
    287      1.1  christos   flags = add_flags | UV_FS_O_RDONLY | UV_FS_O_SYNC;
    288      1.1  christos   openFail(absent_file, UV_ENOENT);
    289  1.1.1.2  christos   writeFail(empty_file, UV_EBADF);
    290      1.1  christos   readExpect(empty_file, "", 0);
    291  1.1.1.2  christos   writeFail(dummy_file, UV_EBADF);
    292      1.1  christos   readExpect(dummy_file, "a", 1);
    293  1.1.1.2  christos   writeFail(empty_dir, UV_EBADF);
    294      1.1  christos   readFail(empty_dir, UV_EISDIR);
    295      1.1  christos 
    296      1.1  christos   /* r+ */
    297      1.1  christos   flags = add_flags | UV_FS_O_RDWR;
    298      1.1  christos   openFail(absent_file, UV_ENOENT);
    299      1.1  christos   writeExpect(empty_file, "bc", 2);
    300      1.1  christos   readExpect(empty_file, "", 0);
    301      1.1  christos   writeExpect(dummy_file, "bc", 2);
    302      1.1  christos   readExpect(dummy_file, "a", 1);
    303      1.1  christos   writeFail(empty_dir, UV_EISDIR);
    304      1.1  christos   readFail(empty_dir, UV_EISDIR);
    305      1.1  christos 
    306      1.1  christos   /* rs+ */
    307      1.1  christos   flags = add_flags | UV_FS_O_RDWR | UV_FS_O_SYNC;
    308      1.1  christos   openFail(absent_file, UV_ENOENT);
    309      1.1  christos   writeExpect(empty_file, "bc", 2);
    310      1.1  christos   readExpect(empty_file, "", 0);
    311      1.1  christos   writeExpect(dummy_file, "bc", 2);
    312      1.1  christos   readExpect(dummy_file, "a", 1);
    313      1.1  christos   writeFail(empty_dir, UV_EISDIR);
    314      1.1  christos   readFail(empty_dir, UV_EISDIR);
    315      1.1  christos 
    316      1.1  christos   /* w */
    317      1.1  christos   flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY;
    318      1.1  christos   writeExpect(absent_file, "bc", 2);
    319  1.1.1.2  christos   readFail(absent_file, UV_EBADF);
    320      1.1  christos   writeExpect(empty_file, "bc", 2);
    321  1.1.1.2  christos   readFail(empty_file, UV_EBADF);
    322      1.1  christos   writeExpect(dummy_file, "bc", 2);
    323  1.1.1.2  christos   readFail(dummy_file, UV_EBADF);
    324      1.1  christos   openFail(empty_dir, UV_EISDIR);
    325      1.1  christos 
    326      1.1  christos   /* wx */
    327      1.1  christos   flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY |
    328      1.1  christos     UV_FS_O_EXCL;
    329      1.1  christos   writeExpect(absent_file, "bc", 2);
    330  1.1.1.2  christos   readFail(absent_file, UV_EBADF);
    331      1.1  christos   openFail(empty_file, UV_EEXIST);
    332      1.1  christos   openFail(dummy_file, UV_EEXIST);
    333      1.1  christos   openFail(empty_dir, UV_EEXIST);
    334      1.1  christos 
    335      1.1  christos   /* w+ */
    336      1.1  christos   flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_RDWR;
    337      1.1  christos   writeExpect(absent_file, "bc", 2);
    338      1.1  christos   readExpect(absent_file, "", 0);
    339      1.1  christos   writeExpect(empty_file, "bc", 2);
    340      1.1  christos   readExpect(empty_file, "", 0);
    341      1.1  christos   writeExpect(dummy_file, "bc", 2);
    342      1.1  christos   readExpect(dummy_file, "", 0);
    343      1.1  christos   openFail(empty_dir, UV_EISDIR);
    344      1.1  christos 
    345      1.1  christos   /* wx+ */
    346      1.1  christos   flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_RDWR |
    347      1.1  christos     UV_FS_O_EXCL;
    348      1.1  christos   writeExpect(absent_file, "bc", 2);
    349      1.1  christos   readExpect(absent_file, "", 0);
    350      1.1  christos   openFail(empty_file, UV_EEXIST);
    351      1.1  christos   openFail(dummy_file, UV_EEXIST);
    352      1.1  christos   openFail(empty_dir, UV_EEXIST);
    353      1.1  christos 
    354      1.1  christos   /* a */
    355      1.1  christos   flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_WRONLY;
    356      1.1  christos   writeExpect(absent_file, "bc", 2);
    357  1.1.1.2  christos   readFail(absent_file, UV_EBADF);
    358      1.1  christos   writeExpect(empty_file, "bc", 2);
    359  1.1.1.2  christos   readFail(empty_file, UV_EBADF);
    360      1.1  christos   writeExpect(dummy_file, "abc", 3);
    361  1.1.1.2  christos   readFail(dummy_file, UV_EBADF);
    362      1.1  christos   writeFail(empty_dir, UV_EISDIR);
    363  1.1.1.2  christos   readFail(empty_dir, UV_EBADF);
    364      1.1  christos 
    365      1.1  christos   /* ax */
    366      1.1  christos   flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_WRONLY |
    367      1.1  christos     UV_FS_O_EXCL;
    368      1.1  christos   writeExpect(absent_file, "bc", 2);
    369  1.1.1.2  christos   readFail(absent_file, UV_EBADF);
    370      1.1  christos   openFail(empty_file, UV_EEXIST);
    371      1.1  christos   openFail(dummy_file, UV_EEXIST);
    372      1.1  christos   openFail(empty_dir, UV_EEXIST);
    373      1.1  christos 
    374      1.1  christos   /* as */
    375      1.1  christos   flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_WRONLY |
    376      1.1  christos     UV_FS_O_SYNC;
    377      1.1  christos   writeExpect(absent_file, "bc", 2);
    378  1.1.1.2  christos   readFail(absent_file, UV_EBADF);
    379      1.1  christos   writeExpect(empty_file, "bc", 2);
    380  1.1.1.2  christos   readFail(empty_file, UV_EBADF);
    381      1.1  christos   writeExpect(dummy_file, "abc", 3);
    382  1.1.1.2  christos   readFail(dummy_file, UV_EBADF);
    383      1.1  christos   writeFail(empty_dir, UV_EISDIR);
    384  1.1.1.2  christos   readFail(empty_dir, UV_EBADF);
    385      1.1  christos 
    386      1.1  christos   /* a+ */
    387      1.1  christos   flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR;
    388      1.1  christos   writeExpect(absent_file, "bc", 2);
    389      1.1  christos   readExpect(absent_file, "", 0);
    390      1.1  christos   writeExpect(empty_file, "bc", 2);
    391      1.1  christos   readExpect(empty_file, "", 0);
    392      1.1  christos   writeExpect(dummy_file, "abc", 3);
    393      1.1  christos   readExpect(dummy_file, "a", 1);
    394      1.1  christos   writeFail(empty_dir, UV_EISDIR);
    395      1.1  christos   readFail(empty_dir, UV_EISDIR);
    396      1.1  christos 
    397      1.1  christos   /* ax+ */
    398      1.1  christos   flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR |
    399      1.1  christos     UV_FS_O_EXCL;
    400      1.1  christos   writeExpect(absent_file, "bc", 2);
    401      1.1  christos   readExpect(absent_file, "", 0);
    402      1.1  christos   openFail(empty_file, UV_EEXIST);
    403      1.1  christos   openFail(dummy_file, UV_EEXIST);
    404      1.1  christos   openFail(empty_dir, UV_EEXIST);
    405      1.1  christos 
    406      1.1  christos   /* as+ */
    407      1.1  christos   flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR |
    408      1.1  christos     UV_FS_O_SYNC;
    409      1.1  christos   writeExpect(absent_file, "bc", 2);
    410      1.1  christos   readExpect(absent_file, "", 0);
    411      1.1  christos   writeExpect(empty_file, "bc", 2);
    412      1.1  christos   readExpect(empty_file, "", 0);
    413      1.1  christos   writeExpect(dummy_file, "abc", 3);
    414      1.1  christos   readExpect(dummy_file, "a", 1);
    415      1.1  christos   writeFail(empty_dir, UV_EISDIR);
    416      1.1  christos   readFail(empty_dir, UV_EISDIR);
    417      1.1  christos }
    418      1.1  christos TEST_IMPL(fs_open_flags) {
    419      1.1  christos   setup();
    420      1.1  christos 
    421      1.1  christos   fs_open_flags(0);
    422      1.1  christos   fs_open_flags(UV_FS_O_FILEMAP);
    423      1.1  christos 
    424      1.1  christos   /* Cleanup. */
    425      1.1  christos   rmdir(empty_dir);
    426      1.1  christos 
    427  1.1.1.3  christos   MAKE_VALGRIND_HAPPY(uv_default_loop());
    428      1.1  christos   return 0;
    429      1.1  christos }
    430      1.1  christos 
    431      1.1  christos #else
    432      1.1  christos 
    433      1.1  christos typedef int file_has_no_tests;  /* ISO C forbids an empty translation unit. */
    434      1.1  christos 
    435      1.1  christos #endif  /* ifndef _WIN32 */
    436