/** * Read environment properties. In particular ones that can't be left until * there is a requirement to log. */ void os_reportInit(os_boolean forceReInit) { static os_boolean doneOnce = OS_FALSE; char *envValue; os_mutexAttr attr; os_result osr; if (!doneOnce || forceReInit) { if (!doneOnce) { osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess) { attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&reportMutex, &attr); } if(osr != os_resultSuccess) { OS_REPORT(OS_WARNING, "os_reportInit", 0, "Unable to create report mutex"); } } doneOnce = OS_TRUE; envValue = os_getenv(os_env_verbosity); if (envValue != NULL) { if (os_reportSetVerbosity(envValue) == os_resultFail) { OS_REPORT_3(OS_WARNING, "os_reportInit", 0, "Cannot parse report verbosity %s value \"%s\"," " reporting verbosity remains %s", os_env_verbosity, envValue, os_reportTypeText[os_reportVerbosity]); } } if (os_procIsOpenSpliceDomainDaemon()) { /** @todo dds2881 - Change default to OS_FALSE ? */ doAppend = OS_TRUE; } envValue = os_getenv(os_env_append); if (envValue != NULL) { os_boolean shouldAppend; if (os_configIsTrue(envValue, &shouldAppend) == os_resultFail) { OS_REPORT_2(OS_WARNING, "os_reportInit", 0, "Cannot parse report %s value \"%s\"," " reporting append mode unchanged", os_env_append, envValue); } else { os_reportSetDoAppend(shouldAppend); } } } }
void server_init() { servers = pmap_new(cstr_t)(); if (!os_getenv("NEOVIM_LISTEN_ADDRESS")) { char *listen_address = (char *)vim_tempname('s'); os_setenv("NEOVIM_LISTEN_ADDRESS", listen_address, 1); free(listen_address); } server_start((char *)os_getenv("NEOVIM_LISTEN_ADDRESS")); }
/// Initializes the module void server_init(void) { servers = pmap_new(cstr_t)(); if (!os_getenv(LISTEN_ADDRESS_ENV_VAR)) { char *listen_address = (char *)vim_tempname(); os_setenv(LISTEN_ADDRESS_ENV_VAR, listen_address, 1); free(listen_address); } server_start((char *)os_getenv(LISTEN_ADDRESS_ENV_VAR)); }
/* return $HOME or the closest we can find */ static const char * get_home(int *free_it) { char *drv, *pth = os_getenv("HOME"); if (pth) return pth; if ((drv = os_getenv("HOMEDRIVE")) && (pth = os_getenv("HOMEPATH"))) { /* looks like WinNT */ char *buf = (char*)pari_malloc(strlen(pth) + strlen(drv) + 1); sprintf(buf, "%s%s",drv,pth); *free_it = 1; return buf; } pth = pari_get_homedir(""); return pth? pth: "."; }
os_int32 os_procGetProcessName( char *procName, os_uint procNameSize) { char* process_name = NULL; char* procPath = NULL; int fileId; struct psinfo info; os_int32 size = 0; if (processName) { process_name = os_getenv("SPLICE_PROCNAME"); processName = (char*) os_malloc(_OS_PROCESS_DEFAULT_NAME_LEN_); *processName = "\0"; if (process_name != NULL) { size = snprintf(processName,_OS_PROCESS_DEFAULT_NAME_LEN_,"%s",process_name); } else { procPath = (char*) os_malloc(_OS_PROCESS_DEFAULT_CMDLINE_LEN_); if (procPath) { snprintf(procPath,_OS_PROCESS_DEFAULT_NAME_LEN_, _OS_PROCESS_PROCFS_PATH_FMT_, os_procIdSelf()); if ((fileId = open( procPath, O_RDONLY, 0555 )) >= 0) { if ( read( fileId, & info, sizeof(info) ) >= 0 ) { snprintf(processName,_OS_PROCESS_DEFAULT_NAME_LEN_,"%s",info.pr_fname); } } os_free(procPath); close( fileId ); } } } size = snprintf(procName, procNameSize, "%s", processName); return size; }
c_bool u_userGetSPBFromEnvUri() { char *uri = NULL; c_bool spb = FALSE; cf_element platformConfig = NULL; cf_element dc = NULL; cf_element elemName = NULL; cf_element singleProcess = NULL; cf_data elementData = NULL; cf_data dataName; c_value value; cfgprs_status r; uri = os_getenv ("OSPL_URI"); r = cfg_parse_ospl (uri, &platformConfig); if (r == CFGPRS_OK) { dc = cf_element (cf_elementChild (platformConfig, CFG_DOMAIN)); if (dc) { singleProcess = cf_element(cf_elementChild(dc, CFG_SINGLEPROCESS)); if (singleProcess != NULL) { elementData = cf_data(cf_elementChild(singleProcess, "#text")); if (elementData != NULL) { value = cf_dataValue(elementData); if (os_strncasecmp(value.is.String, "TRUE", 4) == 0) { /* A SingleProcess value of True implies that Heap is to be used */ spb = TRUE; } } } } } return spb; }
static char *expand_env (const char *name, char op, const char *alt, expand_fn expand) { const char *env = os_getenv (name); switch (op) { case 0: return os_strdup (env ? env : ""); case '-': return env && *env ? os_strdup (env) : expand (alt); case '?': if (env && *env) { return os_strdup (env); } else { char *altx = expand (alt); OS_REPORT (OS_ERROR, "configuration parser", 0, "%s: %s\n", name, altx); os_free (altx); return NULL; } case '+': return env && *env ? expand (alt) : os_strdup (""); default: abort (); return NULL; } }
/* * rpmem_get_ssh_conn_addr -- returns an address which the ssh connection is * established on * * This function utilizes the SSH_CONNECTION environment variable to retrieve * the server IP address. See ssh(1) for details. */ char * rpmem_get_ssh_conn_addr(void) { char *ssh_conn = os_getenv("SSH_CONNECTION"); if (!ssh_conn) { RPMEMC_LOG(ERR, "SSH_CONNECTION variable is not set"); return NULL; } char *sp = strchr(ssh_conn, ' '); if (!sp) goto err_fmt; char *addr = strchr(sp + 1, ' '); if (!addr) goto err_fmt; addr++; sp = strchr(addr, ' '); if (!sp) goto err_fmt; *sp = '\0'; return addr; err_fmt: RPMEMC_LOG(ERR, "invalid format of SSH_CONNECTION variable"); return NULL; }
int u_userGetDomainIdFromEnvUri() { char *uri = NULL; int domainId = 0; cf_element platformConfig = NULL; cf_element dc = NULL; cf_element elemName = NULL; cf_data dataName; c_value value; cfgprs_status r; uri = os_getenv ("OSPL_URI"); r = cfg_parse_ospl (uri, &platformConfig); if (r == CFGPRS_OK) { dc = cf_element (cf_elementChild (platformConfig, CFG_DOMAIN)); if (dc) { elemName = cf_element(cf_elementChild(dc, CFG_ID)); if (elemName) { dataName = cf_data(cf_elementChild(elemName, "#text")); if (dataName != NULL) { value = cf_dataValue(dataName); sscanf(value.is.String, "%d", &domainId); } } } } return domainId; }
void init_homedir(void) { // In case we are called a second time. xfree(homedir); homedir = NULL; const char *var = os_getenv("HOME"); #ifdef WIN32 // Typically, $HOME is not defined on Windows, unless the user has // specifically defined it for Vim's sake. However, on Windows NT // platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for // each user. Try constructing $HOME from these. if (var == NULL) { const char *homedrive = os_getenv("HOMEDRIVE"); const char *homepath = os_getenv("HOMEPATH"); if (homepath == NULL) { homepath = "\\"; } if (homedrive != NULL && strlen(homedrive) + strlen(homepath) < MAXPATHL) { snprintf(os_buf, MAXPATHL, "%s%s", homedrive, homepath); if (os_buf[0] != NUL) { var = os_buf; vim_setenv("HOME", os_buf); } } } #endif if (var != NULL) { #ifdef UNIX // Change to the directory and get the actual path. This resolves // links. Don't do it when we can't return. if (os_dirname((char_u *)os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { var = (char *)IObuff; } if (os_chdir(os_buf) != 0) { EMSG(_(e_prev_dir)); } } #endif homedir = xstrdup(var); } }
/* * get_ssh -- return ssh command name */ static const char * get_ssh(void) { char *cmd = os_getenv(RPMEM_SSH_ENV); if (!cmd) cmd = RPMEM_DEF_SSH; return cmd; }
char * os_locate( const char *name, os_int32 permission) { char *result = NULL; const char *fsep; char *path; char *fullName; os_result osr; std_splitList dirs; int dirsSize; char *curDir; int i; if (name) { fsep = os_fileSep(); /* If the command contains an absolute or relative path, * only check the permissions, otherwise search the file * in the PATH environment */ if ((*name == '.') || (strncmp(name, fsep, strlen(fsep)) == 0)) { osr = os_access(name, permission); if (osr == os_resultSuccess) { result = os_strdup(name); } } else { /* No relative path in name, so walk over the * whole path */ path = os_getenv(PATH_ENVVAR); dirs = std_splitListNew(path, OS_PATHSEPCHAR); dirsSize = std_splitListSize(dirs); for (i=0; (i<dirsSize) && !result; i++) { curDir = std_splitListGet(dirs, i); fullName = (char *)os_malloc( strlen(curDir) + strlen(fsep) + strlen(name) + 1); if (fullName) { os_strcpy(fullName, curDir); os_strcat(fullName, fsep); os_strcat(fullName, name); /* Check file permissions. Do not have to check if file * exists, since permission check fails when the file * does not exist. */ osr = os_access(fullName, permission); if (osr == os_resultSuccess) { result = fullName; } else { os_free(fullName); } } } std_splitListFree(dirs); } } return result; }
void check_for_LD_ASSUME_KERNEL (void) { if (os_getenv ("LD_ASSUME_KERNEL")) { fprintf (stderr, "\nWarning: LD_ASSUME_KERNEL is set, this might cause OpenSpliceDDS to fail.\n"); fprintf (stderr, " OpenSpliceDDS requires the Native Posix Thread Library to be linked.\n"); fprintf (stderr, " You can check by calling: \'ldd `which ospl`', libc.so.* should be linked\n"); fprintf (stderr, " with /lib/tls/libc.so.* and not /lib/i686/libc.so.* nor /lib/libc.so.*.\n\n"); } }
/* * util_suppress_errmsg -- suppresses "abort" window on Windows if env variable * is set, useful for automatic tests */ void util_suppress_errmsg(void) { if (os_getenv("PMDK_NO_ABORT_MSG") != NULL) { DWORD err = GetErrorMode(); SetErrorMode(err | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); } }
/* * rpmemd_print_info -- print basic info and configuration */ static void rpmemd_print_info(struct rpmemd *rpmemd) { RPMEMD_LOG(NOTICE, "ssh connection: %s", _str(os_getenv("SSH_CONNECTION"))); RPMEMD_LOG(NOTICE, "user: %s", _str(os_getenv("USER"))); RPMEMD_LOG(NOTICE, "configuration"); RPMEMD_LOG(NOTICE, "\tpool set directory: '%s'", _str(rpmemd->config.poolset_dir)); RPMEMD_LOG(NOTICE, "\tpersist method: %s", rpmem_persist_method_to_str(rpmemd->persist_method)); RPMEMD_LOG(NOTICE, "\tnumber of threads: %lu", rpmemd->nthreads); RPMEMD_DBG("\tpersist APM: %s", bool2str(rpmemd->config.persist_apm)); RPMEMD_DBG("\tpersist GPSPM: %s", bool2str(rpmemd->config.persist_general)); RPMEMD_DBG("\tuse syslog: %s", bool2str(rpmemd->config.use_syslog)); RPMEMD_DBG("\tlog file: %s", _str(rpmemd->config.log_file)); RPMEMD_DBG("\tlog level: %s", rpmemd_log_level_to_str(rpmemd->config.log_level)); }
char * os_getTempDir() { char * dir_name = NULL; dir_name = os_getenv("OSPL_TEMP"); /* if OSPL_TEMP is not defined the default is /tmp */ if (dir_name == NULL || (strcmp (dir_name, "") == 0)) { dir_name = "/tmp"; } return dir_name; }
static void ut_tmplExpInsertMacro( const ut_tmplExp tmplExp, const os_char *name, const ut_streamOut so, const ut_macroAttrib macroAttrib) { int inserted = 0; ut_streamIn macroStream; ut_macro macro; macro = ut_macroSetGet(tmplExp->macroSet, name); if (macro) { macroStream = ut_streamInNew(ut_macroValue(macro), macroAttrib); while (ut_streamInCur(macroStream) != '\0') { if (ut_streamInCur(macroStream) == macroAttrib->startToken) { ut_tmplExpProcessMacro(tmplExp, macroStream, so); } else { ut_streamOutPut(so, ut_streamInCur(macroStream)); ut_streamInWind(macroStream); } } ut_streamOutPut(so, '\0'); ut_streamInFree(macroStream); inserted = 1; } if (!inserted) { const os_char *value; value = os_getenv((os_char *)name); if (value) { macroStream = ut_streamInNew(value, macroAttrib); while (ut_streamInCur(macroStream) != '\0') { if (ut_streamInCur(macroStream) == macroAttrib->startToken) { ut_tmplExpProcessMacro(tmplExp, macroStream, so); } else { ut_streamOutPut(so, ut_streamInCur(macroStream)); ut_streamInWind(macroStream); } } ut_streamOutPut(so, '\0'); inserted = 1; } } if (!inserted) { fprintf(stderr, "insert_macro: Undefined macro '%s'\n", name); } }
/* has to be freed by the caller */ static os_crtReportInfo setCrtMode( int modeKind, const char *envName, const char *defaultName, const char *prefix) { const char *fileName; char *fullFileName; int size; _HFILE reportFile; os_crtReportInfo result = NULL; fileName = os_getenv(envName); if (!fileName) { fileName = defaultName; } if (strncmp(fileName, REPORTFILE_STDOUT, sizeof(REPORTFILE_STDOUT)) == 0) { reportFile = _CRTDBG_FILE_STDOUT; } else if (strncmp(fileName, REPORTFILE_STDERR, sizeof(REPORTFILE_STDERR)) == 0) { reportFile = _CRTDBG_FILE_STDERR; } else { size = strlen(prefix) + 1 + strlen(fileName) + 1; fullFileName = os_malloc(size); snprintf(fullFileName, size, "%s%c%s", prefix, OS_FILESEPCHAR, fileName);\ reportFile = CreateFile(fullFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (reportFile == INVALID_HANDLE_VALUE) { OS_DEBUG_1("setCrtMode", "Unable to open file \"%s\" for debug reports.", fullFileName); } os_free(fullFileName); } if (reportFile != INVALID_HANDLE_VALUE) { result = os_malloc(sizeof(*result)); result->mode = _CrtSetReportMode(modeKind, _CRTDBG_MODE_FILE); if (result->mode == _CRTDBG_MODE_ERROR) { OS_DEBUG("setCrtMode", "_CrtSetReportMode failed, unable to set report mode to FILE"); } else { result->file = _CrtSetReportFile(_CRT_WARN, reportFile); if (result->file == _CRTDBG_HFILE_ERROR) { OS_DEBUG_1("setCrtMode", "_CrtSetReportFile failed, unable to set report file to \"%s\"", fileName); } } } return result; }
/// Initializes the module bool server_init(void) { ga_init(&servers, sizeof(Server *), 1); bool must_free = false; const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); if (listen_address == NULL) { must_free = true; listen_address = (char *)vim_tempname(); } bool ok = (server_start(listen_address) == 0); if (must_free) { xfree((char *) listen_address); } return ok; }
bool terminfo_is_bsd_console(const char *term) { #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ || defined(__DragonFly__) if (strequal(term, "vt220") // OpenBSD || strequal(term, "vt100")) { // NetBSD return true; } # if defined(__FreeBSD__) // FreeBSD console sets TERM=xterm, but it does not support xterm features // like cursor-shaping. Assume that TERM=xterm is degraded. #8644 return strequal(term, "xterm") && !!os_getenv("XTERM_VERSION"); # endif #else return false; #endif }
/* OS_SYSFILE -- Return the pathname of a system library file. The library * search order is * * IRAFULIB libraries, if any * HSI system libraries (lib, hlib, hbin, etc.) * pkglibs applications libraries, if any * * Hence, the IRAFULIB mechanism may be used to make use of custom copies * of system files (libraries or global include files), whereas the `pkglibs' * mechanism is provided to extend the system library search path to include * applications specified libraries. These are intended to be the global * libraries of installed layered packages, rather than private user libraries * (the IRAFULIB mechanism is better for the latter). */ int os_sysfile ( char *sysfile, /* filename from include statement */ char *fname, /* receives filename */ int maxch ) { register char *ip, *op; char *files, *ip_save; /* Search the standard system libraries and exit if the named * file is found. */ strncpy (fname, irafpath(sysfile), maxch); fname[maxch-1] = EOS; if (strcmp (fname, sysfile) != 0) return (strlen (fname)); /* Search the designated package libraries, if any. */ if ( (files = os_getenv ("pkglibs")) ) { for (ip=files; *ip; ) { /* Get the next library name from the list. */ while (isspace(*ip) || *ip == ',') ip++; for (op=fname; *ip && !isspace(*ip) && *ip != ','; op++) *op = *ip++; *op = EOS; /* Append the target filename. */ for (ip_save=ip, (ip=sysfile); (*op++ = *ip++); ) ; ip = ip_save; /* Exit if the file exists. */ if (os_access (fname, 0, 0)) return (strlen (fname)); } } return (ERR); }
static const os_char * ut_tmplExpMacroValue ( const ut_tmplExp tmplExp, const os_char *name) { ut_macro macro; const char *value; macro = ut_macroSetGet(tmplExp->macroSet, name); if (macro) { return ut_macroValue(macro); } value = os_getenv((os_char*)name); if (value) { return value; } fprintf(stderr, "macro_value: Undefined macro '%s'\n", name); return ""; }
/* * pmem_is_pmem_init -- (internal) initialize Func_is_pmem pointer * * This should be done only once - on the first call to pmem_is_pmem(). * If PMEM_IS_PMEM_FORCE is set, it would override the default behavior * of pmem_is_pmem(). */ static void pmem_is_pmem_init(void) { LOG(3, NULL); static volatile unsigned init; while (init != 2) { if (!util_bool_compare_and_swap32(&init, 0, 1)) continue; /* * For debugging/testing, allow pmem_is_pmem() to be forced * to always true or never true using environment variable * PMEM_IS_PMEM_FORCE values of zero or one. * * This isn't #ifdef DEBUG because it has a trivial performance * impact and it may turn out to be useful as a "chicken bit" * for systems where pmem_is_pmem() isn't correctly detecting * true persistent memory. */ char *ptr = os_getenv("PMEM_IS_PMEM_FORCE"); if (ptr) { int val = atoi(ptr); if (val == 0) Funcs.is_pmem = is_pmem_never; else if (val == 1) Funcs.is_pmem = is_pmem_always; VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Funcs.is_pmem); LOG(4, "PMEM_IS_PMEM_FORCE=%d", val); } if (Funcs.is_pmem == NULL) Funcs.is_pmem = is_pmem_never; if (!util_bool_compare_and_swap32(&init, 1, 2)) FATAL("util_bool_compare_and_swap32"); } }
void os_debugModeInit() { char *pathName; /* Only do this if no-one has called function before * unless os_debugModeExit has been called */ if (!infoBlock) { pathName = os_getenv(REPORTFILE_PATHNAME); if (pathName) { infoBlock = (os_crtReportInfoBlock)os_malloc(sizeof(*infoBlock)); infoBlock->warnInfo = setCrtMode(_CRT_WARN, REPORTFILE_WARNFILENAME, REPORTFILE_WARNDEFAULT, pathName); infoBlock->errorInfo = setCrtMode(_CRT_ERROR, REPORTFILE_ERRORFILENAME, REPORTFILE_ERRORDEFAULT, pathName); infoBlock->assertInfo = setCrtMode(_CRT_ASSERT, REPORTFILE_ASSERTFILENAME, REPORTFILE_ASSERTDEFAULT, pathName); } } }
/// Initializes the module bool server_init(void) { ga_init(&watchers, sizeof(SocketWatcher *), 1); bool must_free = false; const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); if (listen_address == NULL) { must_free = true; listen_address = server_address_new(); } if (!listen_address) { return false; } bool ok = (server_start(listen_address) == 0); if (must_free) { xfree((char *) listen_address); } return ok; }
/* Look for [._]gprc: $GPRC, then in $HOME, ., /etc, pari_datadir */ static FILE * gprc_get(void) { FILE *f = NULL; const char *gprc = os_getenv("GPRC"); if (gprc) f = gprc_chk(gprc); if (!f) { int free_it = 0; const char *home = get_home(&free_it); char *str, *s, c; long l; l = strlen(home); c = home[l-1]; /* + "/gprc.txt" + \0*/ str = strcpy((char*)pari_malloc(l+10), home); if (free_it) pari_free((void*)home); s = str + l; if (c != '/' && c != '\\') *s++ = '/'; #ifndef _WIN32 strcpy(s, ".gprc"); #else strcpy(s, "gprc.txt"); #endif f = gprc_chk(str); /* in $HOME */ if (!f) f = gprc_chk(s); /* in . */ #ifndef _WIN32 if (!f) f = gprc_chk("/etc/gprc"); #else if (!f) /* in basedir */ { const char *basedir = win32_basedir(); char *t = (char *) pari_malloc(strlen(basedir)+strlen(s)+2); sprintf(t, "%s/%s", basedir, s); f = gprc_chk(t); free(t); } #endif pari_free(str); } return f; }
char * u_userGetDomainNameFromEnvUri() { char *uri = NULL; char * domainName = NULL; cf_element platformConfig = NULL; cf_element dc = NULL; cf_element elemName = NULL; cf_data dataName; c_value value; cfgprs_status r; uri = os_getenv ("OSPL_URI"); if ( uri != NULL ) { domainName = os_strdup(uri); } else { r = cfg_parse_ospl (uri, &platformConfig); if (r == CFGPRS_OK) { dc = cf_element (cf_elementChild (platformConfig, CFG_DOMAIN)); if (dc) { elemName = cf_element(cf_elementChild(dc, CFG_NAME)); if (elemName) { dataName = cf_data(cf_elementChild(elemName, "#text")); if (dataName != NULL) { value = cf_dataValue(dataName); domainName = os_strdup(value.is.String); } } } } } return domainName; }
u_domain u_userLookupDomain( const c_char *uri) { u_user u; u_domain domain; u_domainAdmin ka; c_long i; domain = NULL; u = u__userLock(); if (u) { if (uri == NULL || strlen (uri) == 0) { uri = os_getenv ("OSPL_URI"); if (uri == NULL) { uri = ""; } } /* If the domain is already opened by the process, return the domain object. Otherwise open the domain and add to the administration */ for (i=1; (i<=u->domainCount && domain == NULL); i++) { ka = &u->domainList[i]; if (u_domainCompareDomainId(ka->domain,(void *)uri)) { domain = ka->domain; } } u__userUnlock(); } else { OS_REPORT(OS_ERROR, "u_userLookupDomain",0, "User layer not initialized"); } return domain; }
static int idl_genInterface( idl_scope scope, const char *name, char *class_base, idl_typeSpec typeSpec, c_bool generateInterfaceClass) { idl_tmplExp te; c_char tmplFileName[1024]; c_char pname[1024]; c_char *tmplPath; c_char *orbPath; int tmplFile; struct os_stat_s tmplStat; unsigned int nRead; os_char *redirects; char *scopedMetaTypeName; const char *internalTypeName; const char *keyList; char *scopeStackJavaDot = idl_scopeStackJava(scope, ".", name); char *scopeStackJavaSlash = idl_scopeStackJava(scope, "/", name); char *typeSpecName = idl_typeSpecName(typeSpec); char *javaId = idl_javaId(name); int result = 0; tmplPath = os_getenv("OSPL_TMPL_PATH"); orbPath = os_getenv("OSPL_ORB_PATH"); if (tmplPath == NULL) { printf("OSPL_TMPL_PATH not defined\n"); result = -1; goto err_exit; } if (orbPath == NULL) { printf("OSPL_ORB_PATH not defined\n"); result = -1; goto err_exit; } idlpp_macroSet = idl_macroSetNew(); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("type-name", javaId)); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("actual-type-name", typeSpecName)); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-type-name", scopeStackJavaDot)); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-class-name", scopeStackJavaSlash)); redirects = idl_packageRedirects (); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-package-redirects", redirects)); os_free(redirects); scopedMetaTypeName = idl_scopeStack(scope, "::", name); internalTypeName = idl_internalTypeNameForBuiltinTopic(scopedMetaTypeName); keyList = idl_keyResolve(idl_keyDefDefGet(), scope, name); if ((strlen(internalTypeName) != 0) && ((keyList == NULL) || (strcmp(keyList,"key") == 0))) { keyList = "key.localId,key.systemId"; } idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-meta-type-name", scopedMetaTypeName)); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("internal-type-name", internalTypeName)); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-actual-type-name", idl_corbaJavaTypeFromTypeSpec(typeSpec))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("key-list", keyList)); os_free(scopedMetaTypeName); /* Generate only in standalone mode */ if (idl_getCorbaMode() == IDL_MODE_STANDALONE) { snprintf(pname, sizeof (pname), "%s%s", javaId, class_base); idl_openJavaPackage(scope, pname); if (idl_fileCur() == NULL) { result = -1; goto err_exit; } /* Prepare Interface class */ if (generateInterfaceClass) { snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%s.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base); /* QAC EXPECT 3416; No side effects here */ if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) || (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) { printf ("No template found or protection violation (%s)\n", tmplFileName); result = -1; goto err_exit; } /* QAC EXPECT 5007; will not use wrapper */ idlpp_template = os_malloc(tmplStat.stat_size+1); tmplFile = open(tmplFileName, O_RDONLY); nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size); memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead); close(tmplFile); idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); te = idl_tmplExpNew(idlpp_macroSet); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); os_free(idlpp_template); } idl_closeJavaPackage(); snprintf(pname, sizeof(pname), "%s%sHolder", javaId, class_base); idl_openJavaPackage(scope, pname); if (idl_fileCur() == NULL) { result = -1; goto err_exit; } /* Prepare typeSupportHolder class */ snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sHolder.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base); /* QAC EXPECT 3416; No side effects here */ if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) || (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) { printf ("No template found or protection violation (%s)\n", tmplFileName); result = -1; goto err_exit; } /* QAC EXPECT 5007; will not use wrapper */ idlpp_template = os_malloc(tmplStat.stat_size+1); tmplFile = open(tmplFileName, O_RDONLY); nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size); memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead); close(tmplFile); idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); os_free(idlpp_template); te = idl_tmplExpNew(idlpp_macroSet); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); idl_closeJavaPackage(); snprintf(pname, sizeof(pname), "%s%sHelper", javaId, class_base); idl_openJavaPackage(scope, pname); if (idl_fileCur() == NULL) { result = -1; goto err_exit; } /* Prepare typeSupportHelper class */ snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sHelper.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base); /* QAC EXPECT 3416; No side effects here */ if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) || (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) { printf ("No template found or protection violation (%s)\n", tmplFileName); result = -1; goto err_exit; } /* QAC EXPECT 5007; will not use wrapper */ idlpp_template = os_malloc(tmplStat.stat_size+1); tmplFile = open(tmplFileName, O_RDONLY); nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size); memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead); close(tmplFile); idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); os_free(idlpp_template); te = idl_tmplExpNew(idlpp_macroSet); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); idl_closeJavaPackage(); snprintf(pname, sizeof(pname), "%s%sOperations", javaId, class_base); idl_openJavaPackage(scope, pname); if (idl_fileCur() == NULL) { result = idl_abort; goto err_exit; } /* Prepare typeSupportOperations class */ snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sOperations.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base); /* QAC EXPECT 3416; No side effects here */ if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) || (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) { printf ("No template found or protection violation (%s)\n", tmplFileName); result = -1; goto err_exit; } /* QAC EXPECT 5007; will not use wrapper */ idlpp_template = os_malloc(tmplStat.stat_size+1); tmplFile = open(tmplFileName, O_RDONLY); nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size); memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead); close(tmplFile); idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); os_free(idlpp_template); te = idl_tmplExpNew(idlpp_macroSet); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); idl_closeJavaPackage(); } if (generateInterfaceClass) { /* Implementation with Impl extension */ snprintf(pname, sizeof(pname), "%s%sImpl", javaId, class_base); } else { /* Implementation without Impl extension */ snprintf(pname, sizeof(pname), "%s%s", javaId, class_base); } idl_openJavaPackage(scope, pname); if (idl_fileCur() == NULL) { result = -1; goto err_exit; } /* Prepare typeSupportStub class */ snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sImpl.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base); /* QAC EXPECT 3416; No side effects here */ if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) || (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) { printf("No template found or protection violation (%s)\n", tmplFileName); result = idl_abort; goto err_exit; } /* QAC EXPECT 5007; will not use wrapper */ idlpp_template = os_malloc(tmplStat.stat_size+1); tmplFile = open(tmplFileName, O_RDONLY); nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size); memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead); close(tmplFile); idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); os_free(idlpp_template); te = idl_tmplExpNew(idlpp_macroSet); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); idl_closeJavaPackage(); err_exit: os_free(javaId); os_free(scopeStackJavaDot); os_free(scopeStackJavaSlash); return result; }
static int idl_genTypeSeqHolder( idl_scope scope, const char *name, idl_typeSpec typeSpec) { idl_tmplExp te; c_char tmplFileName[1024]; c_char pname[1024]; c_char *tmplPath; c_char *orbPath; int tmplFile; struct os_stat_s tmplStat; unsigned int nRead; tmplPath = os_getenv("OSPL_TMPL_PATH"); orbPath = os_getenv("OSPL_ORB_PATH"); if (tmplPath == NULL) { printf("OSPL_TMPL_PATH not defined\n"); return -1; } if (orbPath == NULL) { printf("OSPL_ORB_PATH not defined\n"); return -1; } idlpp_macroSet = idl_macroSetNew(); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("type-name", idl_javaId(name))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("actual-type-name", idl_typeSpecName(typeSpec))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-type-name", idl_scopeStackJava(scope, ".", name))); idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-actual-type-name", idl_corbaJavaTypeFromTypeSpec(typeSpec))); snprintf(pname, sizeof (pname), "%sSeqHolder", idl_javaId(name)); idl_openJavaPackage(scope, pname); if (idl_fileCur() == NULL) { return -1; } /* Prepare typeSupport class */ snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmplSeqHolder.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR); /* QAC EXPECT 3416; No side effects here */ if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) || (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) { printf("No template found or protection violation (%s)\n", tmplFileName); return -1; } /* QAC EXPECT 5007; will not use wrapper */ idlpp_template = os_malloc(tmplStat.stat_size+1); tmplFile = open(tmplFileName, O_RDONLY); nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size); memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead); close(tmplFile); idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE); idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib); te = idl_tmplExpNew(idlpp_macroSet); idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur()); idl_streamInFree(idlpp_inStream); idl_tmplExpFree(te); idl_closeJavaPackage(); return 0; }