+static char* path_name = NULL;
+FILE *surf_fopen(const char *name, const char *mode)
+{
+ int i;
+ char* path = NULL;
+ FILE *file = NULL;
+
+ xbt_assert1((name!=NULL), "Need a real file name, not \"%s\"\n",name);
+
+ xbt_assert0(surf_path,"surf_init has to be called before using surf_fopen");
+ if(!path_name) path_name=xbt_new0(char,strlen(name)+1);
+
+ xbt_dynar_foreach(surf_path,i,path) {
+ if(strlen(path_name)<strlen(path)+strlen(name)+2)
+ path_name=xbt_realloc(path_name,strlen(path)+strlen(name)+2);
+ strcpy(path_name, path);
+ strcat(path_name,"/");
+ strcat(path_name,name);
+ file = fopen(path_name,mode);
+ if(file) return file;
+ }
+ return file;
+}
+