1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * This test calls PR_OpenFile to create a bunch of files
40 * with various file modes.
50 #define TEMPLATE_FILE_NAME "template.txt"
60 /* Write in text mode. Let stdio deal with line endings. */
61 template = fopen(TEMPLATE_FILE_NAME
, "w");
62 fputs("line 1\nline 2\n", template);
65 /* Read in binary mode */
66 fd
= PR_OpenFile(TEMPLATE_FILE_NAME
, PR_RDONLY
, 0666);
67 nbytes
= PR_Read(fd
, buf
, sizeof(buf
));
69 PR_Delete(TEMPLATE_FILE_NAME
);
71 fd
= PR_OpenFile("tfil0700.txt", PR_RDWR
| PR_CREATE_FILE
, 0700);
73 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
74 PR_GetError(), PR_GetOSError());
77 PR_Write(fd
, buf
, nbytes
);
80 fd
= PR_OpenFile("tfil0500.txt", PR_RDWR
| PR_CREATE_FILE
, 0500);
82 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
83 PR_GetError(), PR_GetOSError());
86 PR_Write(fd
, buf
, nbytes
);
89 fd
= PR_OpenFile("tfil0400.txt", PR_RDWR
| PR_CREATE_FILE
, 0400);
91 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
92 PR_GetError(), PR_GetOSError());
95 PR_Write(fd
, buf
, nbytes
);
98 fd
= PR_OpenFile("tfil0644.txt", PR_RDWR
| PR_CREATE_FILE
, 0644);
100 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
101 PR_GetError(), PR_GetOSError());
104 PR_Write(fd
, buf
, nbytes
);
107 fd
= PR_OpenFile("tfil0664.txt", PR_RDWR
| PR_CREATE_FILE
, 0664);
109 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
110 PR_GetError(), PR_GetOSError());
113 PR_Write(fd
, buf
, nbytes
);
116 fd
= PR_OpenFile("tfil0660.txt", PR_RDWR
| PR_CREATE_FILE
, 0660);
118 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
119 PR_GetError(), PR_GetOSError());
122 PR_Write(fd
, buf
, nbytes
);
125 fd
= PR_OpenFile("tfil0666.txt", PR_RDWR
| PR_CREATE_FILE
, 0666);
127 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
128 PR_GetError(), PR_GetOSError());
131 PR_Write(fd
, buf
, nbytes
);
134 fd
= PR_OpenFile("tfil0640.txt", PR_RDWR
| PR_CREATE_FILE
, 0640);
136 fprintf(stderr
, "PR_OpenFile failed (%d, %d)\n",
137 PR_GetError(), PR_GetOSError());
140 PR_Write(fd
, buf
, nbytes
);