Fix unmatched temporary buffer allocations
[yaffs2.git] / direct / test-framework / timothy_tests / yaffs_and_linux_mirror_tests / yaffs_test_write.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 "yaffs_test_write.h"
14
15 int yaffs_test_write(arg_temp *args_struct)
16 {
17         char path[200];
18         char message[200];
19         int output=0,output2=0;
20         int handle;
21         struct yaffs_stat yaffs_stat_struct;
22         join_paths(yaffs_struct.root_path,args_struct->string1, path );
23         sprintf(message,"trying to write to: %s\nwith mode set to %o \n",path,args_struct->char1);
24         print_message(3,message);
25         printf("mode S_IREAD %d S_IWRITE %d\n",(args_struct->char2 & S_IREAD),(args_struct->char2 & S_IWRITE));
26         handle=yaffs_open(path,((args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND))|O_RDWR),(args_struct->char2&(S_IREAD|S_IWRITE)));
27         printf("handle %d\n",handle);
28         if (handle<0){
29                 print_message(3,"failed to open a handle\n");
30                 return -1; //handle failed to open
31         }
32
33 /*      output=yaffs_fstat(handle,&yaffs_stat_struct);
34         if (output < 0){
35                 sprintf(message,"failed to stat the file\n");
36                 print_message(3,message);
37                 get_error_yaffs();
38         } else {
39                 sprintf(message,"stated the file\n");
40                 print_message(3,message);
41                 sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
42                 print_message(3,message);
43                 sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
44                 print_message(3,message);       
45         }
46
47         sprintf(message,"trying to write: %d bytes into the file\n",strlen(args_struct->string2));
48         print_message(3,message);
49 */      
50         output=yaffs_write(handle,&args_struct->string2,strlen(args_struct->string2));
51
52 /*      print_message(3,"\n wrote to the file\n");
53         output2=yaffs_fstat(handle,&yaffs_stat_struct);
54         if (output2 < 0){
55                 sprintf(message,"failed to stat the file\n");
56                 print_message(3,message);
57                 get_error_yaffs();
58         } else {
59                 sprintf(message,"stated the file\n");
60                 print_message(3,message);
61                 sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
62                 print_message(3,message);
63                 sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
64                 print_message(3,message);       
65         }
66 */      yaffs_close(handle);
67 /*      print_message(3,"\n closing the file\n");
68         output2=yaffs_stat(path,&yaffs_stat_struct);
69         if (output2 < 0){
70                 sprintf(message,"failed to stat the file\n");
71                 print_message(3,message);
72                 get_error_yaffs();
73         } else {
74                 sprintf(message,"stated the file\n");
75                 print_message(3,message);
76                 sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
77                 print_message(3,message);
78                 sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
79                 print_message(3,message);       
80         }
81 */
82
83         return output;
84 }