Example #1
0
int
ocinternalinitialize(void)
{
    int stat = OC_NOERR;

    if(!ocglobalstate.initialized) {
        memset((void*)&ocglobalstate,0,sizeof(ocglobalstate));
	ocglobalstate.initialized = 1;
    }

    /* Capture $HOME */
    {
	char* p;
	char* q;
        char* home = getenv("HOME");
	char cwd[4096];
        if(ocglobalstate.home == NULL) {
#if defined(_WIN32) || defined(_WIN64)
	    home = getenv("TEMP");
#else
	    home = "/tmp";
#endif
	}
        if(home == NULL) {
	    home = getcwd(cwd,sizeof(cwd));
	    if(home == NULL || *home == '\0') home = ".";
	}

        /* Convert '\' to '/' */
        ocglobalstate.home = (char*)malloc(strlen(home) + 1);
	for(p=home,q=ocglobalstate.home;*p;p++,q++) {
	    if(*p == '\\') {*q = '/'; } else {*q = *p;}
	}
	*q = '\0';
    }

    /* Compute some xdr related flags */
    xxdr_init();

    ocloginit();

    oc_curl_protocols(&ocglobalstate); /* see what protocols are supported */

    /* compile the .dodsrc, if any */
    {
        char* path = NULL;
	char** alias;
	FILE* f = NULL;
        /* locate the configuration files: . first in '.',  then $HOME */
	for(alias=rcfilenames;*alias;alias++) {
	    size_t pathlen = strlen("./")+strlen(*alias)+1;
            path = (char*)malloc(pathlen);
	    if(path == NULL) return OC_ENOMEM;
	    if(!occopycat(path,pathlen,2,"./",*alias)) {
	        if(path) free(path);
		return OC_EOVERRUN;
	    }
  	    /* see if file is readable */
	    f = fopen(path,"r");
	    if(f != NULL) break;
    	    if(path != NULL) {free(path); path = NULL;} /* cleanup */
	}
	if(f == NULL) { /* try $HOME */
	    OCASSERT(path == NULL);
	    for(alias=rcfilenames;*alias;alias++) {
		size_t pathlen = strlen(ocglobalstate.home)+1+strlen(*alias)+1;
	        path = (char*)malloc(pathlen);
	        if(path == NULL) return OC_ENOMEM;
		if(!occopycat(path,pathlen,3,ocglobalstate.home,"/",*alias)) {
		    if(path) free(path);
		    return OC_EOVERRUN;
		}
		f = fopen(path,"r");
		if(f != NULL) break;
 	        if(path != NULL) {free(path); path=NULL;}
            }
	}
        if(f == NULL) {
            oclog(OCLOGDBG,"Cannot find runtime configuration file");
	} else {
	    OCASSERT(path != NULL);
       	    fclose(f);
            if(ocdebug > 1)
		fprintf(stderr, "DODS RC file: %s\n", path);
            if(ocdodsrc_read(*alias,path) == 0)
	        oclog(OCLOGERR, "Error parsing %s\n",path);
        }
        if(path != NULL) free(path);
    }

    return OCTHROW(stat);
}
Example #2
0
OCerror
ocinternalinitialize(void)
{
    int stat = OC_NOERR;

#if 0
    if(sizeof(off_t) != sizeof(void*)) {
      fprintf(stderr,"OC xxdr depends on the assumption that sizeof(off_t) == sizeof(void*)\n");
      //Commenting out for now, as this does not hold true on 32-bit
      //linux systems.
      //OCASSERT(sizeof(off_t) == sizeof(void*));
    }
#endif

    if(!ocglobalstate.initialized) {
      memset((void*)&ocglobalstate,0,sizeof(ocglobalstate));
      ocglobalstate.initialized = 1;
    }

    /* Capture temp dir*/
    {
	char* tempdir;
	char* p;
	char* q;
	char cwd[4096];
#if defined(_WIN32) || defined(_WIN64)
        tempdir = getenv("TEMP");
#else
	tempdir = "/tmp";
#endif
        if(tempdir == NULL) {
	    fprintf(stderr,"Cannot find a temp dir; using ./\n");
	    tempdir = getcwd(cwd,sizeof(cwd));
	    if(tempdir == NULL || *tempdir == '\0') tempdir = ".";
	}
        ocglobalstate.tempdir= (char*)malloc(strlen(tempdir) + 1);
	for(p=tempdir,q=ocglobalstate.tempdir;*p;p++,q++) {
	    if((*p == '/' && *(p+1) == '/')
	       || (*p == '\\' && *(p+1) == '\\')) {p++;}
	    *q = *p;
	}
	*q = '\0';
#if defined(_WIN32) || defined(_WIN64)
#else
        /* Canonicalize */
	for(p=ocglobalstate.tempdir;*p;p++) {
	    if(*p == '\\') {*p = '/'; };
	}
	*q = '\0';
#endif
    }

    /* Capture $HOME */
    {
	char* p;
	char* q;
        char* home = getenv("HOME");

        if(home == NULL) {
	    /* use tempdir */
	    home = ocglobalstate.tempdir;
	}
        ocglobalstate.home = (char*)malloc(strlen(home) + 1);
	for(p=home,q=ocglobalstate.home;*p;p++,q++) {
	    if((*p == '/' && *(p+1) == '/')
	       || (*p == '\\' && *(p+1) == '\\')) {p++;}
	    *q = *p;
	}
	*q = '\0';
#if defined(_WIN32) || defined(_WIN64)
#else
        /* Canonicalize */
	for(p=home;*p;p++) {
	    if(*p == '\\') {*p = '/'; };
	}
#endif
    }

    /* Compute some xdr related flags */
    xxdr_init();

    ocloginit();

    oc_curl_protocols(&ocglobalstate); /* see what protocols are supported */

    return OCTHROW(stat);
}
Example #3
0
int
ocinternalinitialize(void)
{
    int stat = OC_NOERR;

    if(!ocglobalstate.initialized) {
        memset((void*)&ocglobalstate,0,sizeof(ocglobalstate));
	ocglobalstate.initialized = 1;
    }

    /* Compute some xdr related flags */
    xxdr_init();

    ocloginit();

    oc_curl_protocols(&ocglobalstate); /* see what protocols are supported */

    /* compile the .dodsrc, if any */
    {
        char* path = NULL;
        char* homepath = NULL;
	char** alias;
	FILE* f = NULL;
        /* locate the configuration files: . first in '.',  then $HOME */
	for(alias=rcfilenames;*alias;alias++) {
	    size_t pathlen = strlen("./")+strlen(*alias)+1;
            path = (char*)malloc(pathlen);
	    if(path == NULL) return OC_ENOMEM;
	    if(!occopycat(path,pathlen,2,"./",*alias)) {
	      if(path) free(path);
	      return OC_EOVERRUN;
	    }
  	    /* see if file is readable */
	    f = fopen(path,"r");
	    if(f != NULL) break;
    	    if(path != NULL) {free(path); path = NULL;} /* cleanup */
	}
	if(f == NULL) { /* try $HOME */
	    OCASSERT(path == NULL);
            homepath = getenv("HOME");
            if (homepath!= NULL) {
	        for(alias=rcfilenames;*alias;alias++) {
	            size_t pathlen = strlen(homepath)+1+strlen(*alias)+1;
	            path = (char*)malloc(pathlen);
	            if(path == NULL) return OC_ENOMEM;
		    if(!occopycat(path,pathlen,3,homepath,"/",*alias)) {
		      if(path) {free(path);}
		      return OC_EOVERRUN;
		    }
		    f = fopen(path,"r");
		    if(f != NULL) break;
 	            if(path != NULL) {free(path); path=NULL;}
		}
            }
	}
        if(f == NULL) {
            oclog(OCLOGDBG,"Cannot find runtime configuration file");
	} else {
	    OCASSERT(path != NULL);
       	    fclose(f);
            if(ocdebug > 1)
		fprintf(stderr, "DODS RC file: %s\n", path);
            if(ocdodsrc_read(*alias,path) == 0)
	        oclog(OCLOGERR, "Error parsing %s\n",path);
        }
        if(path != NULL) free(path);
    }
    return OCTHROW(stat);
}