eaa97da34ec66112f990393d3b9307a80eb0698f
[yaffs2.git] / direct / timothy_tests / mirror_tests / yaffs_test_write.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include "yaffs_test_write.h"
15
16 int yaffs_test_write(arg_temp *args_struct)
17 {
18         char path[200];
19         char message[200];
20         int output=0;
21         int handle;
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         handle=yaffs_open(path,args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND),args_struct->char2&(S_IREAD|S_IWRITE));
26         if (handle<0){
27                 print_message(3,"failed to open a handle\n");
28                 return -1; //handle failed to open
29         }
30         sprintf(message,"trying to write: %d bytes into the file\n",strlen(args_struct->string2));
31         print_message(3,message);
32         output=yaffs_write(handle,args_struct->string2,strlen(args_struct->string2));
33         yaffs_close(handle);
34         return output;
35 }