Fix copyright
[yaffs2.git] / direct / test-framework / timothy_tests / quick_tests / test_yaffs_open_EACCES.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2018 Aleph One Ltd.
5  *
6  * Created by Timothy Manning <timothy@yaffs.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include "test_yaffs_open_EACCES.h"
14
15 static int handle = -1;
16
17 int test_yaffs_open_EACCES(void)
18 {
19         int error_code=0;
20         int output =-1;
21         if (yaffs_access(FILE_PATH,0)!=0){
22                 
23                 handle = yaffs_open(FILE_PATH, O_CREAT | O_RDWR, FILE_MODE);
24
25                 output=yaffs_close(handle);
26                 if (output<0){
27                         print_message("failed to open file\n",2);
28                         return -1;
29                 }
30         }
31
32         output=yaffs_chmod(FILE_PATH,S_IREAD);
33         if (output<0){
34                 print_message("failed to chmod file\n",2);
35                 return -1;
36         }
37         handle=yaffs_open(FILE_PATH, O_TRUNC| O_RDWR,FILE_MODE );
38         if (handle <0){
39                 error_code=yaffs_get_error();
40                 if (abs(error_code)==EACCES){
41                         return 1;
42                 }
43                 else {
44                         print_message("different error than expected\n",2);
45                         return -1;
46                 }
47         }
48         else {
49                 print_message("file opened with read and write permissions, chmoded to read only.(which is a bad thing)\n",2);
50                 return -1;
51         }
52 }
53
54 int test_yaffs_open_EACCES_clean(void)
55 {
56         int output= -1;
57         int output2=-1; 
58         if (handle >=0){
59                 output2= yaffs_close(handle);
60         }
61         output=yaffs_chmod(FILE_PATH,S_IREAD|S_IWRITE);
62         if (output<0){
63                 print_message("failed to chmod file\n",2);
64                 return -1;
65         }
66         return (output2&&output);
67         
68 }
69