2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: commonfuncs.cxx,v 1.3 2003/02/27 08:27:51 leo Exp $
18 #include "commonfuncs.h"
21 //===========================================================================
22 /// global find_full_path_for_file(char* fname, char* ret_full_pathname, FMode mode)
23 /// find file in global and local dirs and return full pathname
25 bool find_full_path_for_file(char* name
, char* ret_full_pathname
, FMode mode
)
29 char *home
=getenv("HOME");
30 mode_t fmode
=O_RDONLY
;
44 sprintf(ret_full_pathname
,"%s/%s",GLOBAL_SEARCH
,name
); //First check in GLOBAL_SEARCH dir
45 fd
=open(ret_full_pathname
,fmode
);
49 sprintf(ret_full_pathname
,"%s/%s/%s",home
,LOCAL_SEARCH
,name
); //Then in LOCAL one
50 fd
=open(ret_full_pathname
,fmode
);
54 sprintf(ret_full_pathname
,"./%s",name
); //Then in current dir
55 fd
=open(ret_full_pathname
,fmode
);
59 sprintf(ret_full_pathname
,"./data/%s",name
); //And finally in ./data
60 fd
=open(ret_full_pathname
,fmode
);
64 fprintf(stderr
,"ERROR: Can't find file %s in:\n\t./\n\t./data\n\t%s/%s\n\t%s\n",
65 name
,home
,LOCAL_SEARCH
,GLOBAL_SEARCH
);
73 sprintf(ret_full_pathname
,"data\\%s",name
); //And finally in ./data
74 fp
=fopen(ret_full_pathname
, "r");