a9aecf78bcfec571954a46202df59b74cef16454
[yaffs2.git] / direct / timothy_tests / quick_tests / lib.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 "lib.h"
15
16 static int EXIT_ON_ERROR = 1;
17 static int  PRINT_LEVEL = 2;    //This sets the level of detail which is printed. There are 3 levels 0,1,2 and 3  
18                         //0 just prints the number of tests passed and failed.
19                         //1 is the basic print level. it will print the details of a failed test.
20                         //2 will print if a test passes and cleans. 
21 void set_print_level(int new_level)
22 {
23         PRINT_LEVEL=new_level;
24 }
25
26 void set_exit_on_error(int num)
27 {
28         EXIT_ON_ERROR=num;
29 }
30
31 int get_exit_on_error(void)
32 {
33         return EXIT_ON_ERROR;
34 }
35
36
37 int set_up_ELOOP(void){
38         int output1=1;
39         int output2=1;
40         if (0!=yaffs_access(ELOOP2)){
41                 output1=yaffs_symlink(ELOOP,ELOOP2);
42         }       
43         if (0!=yaffs_access(ELOOP)){
44                 output2=yaffs_symlink(ELOOP2,ELOOP);
45         }
46         return (output1|output2);
47 }
48
49 void join_paths(char *path1,char *path2,char *new_path )
50 {
51
52         //strcat(new_path,path1);       /*since all functions have this then pull it out*/
53         if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
54                 /*paths are compatiable. concatanate them. note -2 is because of \0*/  
55                 strcat(new_path,path1);
56                 strcat(new_path,path2);         
57                 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
58                 //strcpy(new_path,strcat(path1,path2)); 
59                 //return new_path;
60         } else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
61                 /*paths are compatiable. concatanate them*/  
62                 strcat(new_path,path1);
63                 strcat(new_path,path2);         
64
65         } else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
66                         /*need to add a "/". */  
67                 strcat(new_path,path1);
68                 strcat(new_path,"/");
69                 strcat(new_path,path2);
70
71         } else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
72                 /*need to remove a "/". */
73                 /*yaffs does not mind the extra slash. */               
74                 strcat(new_path,path1);
75                 strcat(new_path,path2);
76
77         } else {
78                 //error 
79                 //return -1;
80         }
81 }
82
83 void print_message(char *message,char print_level)
84 {
85         if (print_level <= PRINT_LEVEL){
86                 printf(message);
87         }
88 }
89         
90
91