Esempio n. 1
0
/*>void FreeWholePDB(WHOLEPDB *wpdb)
   ---------------------------------
   Input:     WHOLEPDB    *wpdb    WHOLEPDB structure to be freed

   Frees the header, trailer and atom content from a WHOLEPDB structure

   30.05.02  Original   By: ACRM
*/
void FreeWholePDB(WHOLEPDB *wpdb)
{
   FreeStringList(wpdb->header);
   FreeStringList(wpdb->trailer);
   FREELIST(wpdb->pdb, PDB);
   free(wpdb);
}
Esempio n. 2
0
void I_EndGlob(glob_t *glob)
{
    if (glob == NULL)
    {
        return;
    }

    FreeStringList(glob->globs, glob->num_globs);
    FreeStringList(glob->filenames, glob->filenames_len);

    free(glob->directory);
    free(glob->last_filename);
    (void) closedir(glob->dir);
    free(glob);
}
Esempio n. 3
0
short LoadKeyTextList( void )
{
	KeyTextList* list;
	char* pathname = NULL;
	short  result = -1;

	if( !g_keytext_dir  ) goto Err1; 

	if( (pathname = CheckFileExists(g_keytext_dir, CNIJLGMON2_RESFILE)) == NULL ){
		if( (pathname = CheckFileExists("keytext", CNIJLGMON2_RESFILE)) == NULL )  goto Err1;
	}

	if ( (list = (KeyTextList*)malloc(sizeof(KeyTextList))) == NULL ) goto Err1;

	if( (list->tree = CreateTree()) == NULL ) goto Err2;

	if( ReadXMLFile(pathname, list->tree) != 0 ) goto Err3;

	g_key_keytext_list = list;

	result = 0;
	return result;
Err3:
	FreeStringList( list->tree );
Err2:
	free( list );
Err1:
	return result;
}
Esempio n. 4
0
void PediaMainForm::doDbSelected(int selectedStr)
{
    if (NOT_SELECTED == selectedStr)
        goto Exit;

    char_t *fullName = app().strList[selectedStr];
    // a hack: lang is what is inside "(" and ")"
    while (*fullName && (*fullName!='('))
        ++fullName;
    assert(*fullName);
    char_t *langName = fullName+1;
    langName[2] = '\0';

    LookupManager* lookupManager=app().getLookupManager(true);
    assert(NULL != lookupManager);

    if (lookupManager && !lookupManager->lookupInProgress())
    {
        lookupManager->switchDatabase(langName);
    }

Exit:
    FreeStringList(app().strList, app().strListSize);
    app().strList = NULL;
}
Esempio n. 5
0
void PediaMainForm::clearLangCodes()
{
    if (bootstrapLangCodes != availLangCodes_)
    {
        FreeStringList(availLangCodes_, availLangCodesCount_);
        availLangCodes_ = (char**)bootstrapLangCodes;
        availLangCodesCount_ = ARRAY_SIZE(bootstrapLangCodes);
    }
}
Esempio n. 6
0
void FreeKeyTextList( void )
{
	if ( g_key_keytext_list == NULL ) return;

	FreeStringList( g_key_keytext_list->tree );
	free( g_key_keytext_list );
	g_key_keytext_list = NULL;
	
}
Esempio n. 7
0
void PediaMainForm::doLookupSelectedTerm(int selectedStr)
{
    if (NOT_SELECTED==selectedStr)
        goto Exit;

    const char_t* term = app().strList[selectedStr];

    LookupManager* lookupManager=app().getLookupManager(true);
    if (lookupManager && !lookupManager->lookupInProgress())
        lookupManager->lookupIfDifferent(term, app().preferences().currentLang);

Exit:

    FreeStringList(app().strList, app().strListSize);
    app().strList = NULL;
}
 //Teardown
 ~EnchantDictionarySuggestTestFixtureBase()
 {
     FreeStringList(_suggestions);
 }
Esempio n. 9
0
EFI_HANDLE
ParseGuidedSectionToolsMemoryFile (
  IN EFI_HANDLE    InputFile
  )
/*++

Routine Description:

  This function parses the tools_def.txt file.  It returns a
  EFI_HANDLE object which can be used for the other library
  functions and should be passed to FreeParsedGuidedSectionToolsHandle
  to free resources when the tools_def.txt information is no
  longer needed.

Arguments:

  InputFile     Memory file image.

Returns:

  NULL if error or EOF
  InputBuffer otherwise

--*/
{
  EFI_STATUS  Status;
  CHAR8       *NextLine;
  STRING_LIST *Tool;
  EFI_GUID    Guid;
  GUID_SEC_TOOL_ENTRY *FirstGuidTool;
  GUID_SEC_TOOL_ENTRY *LastGuidTool;
  GUID_SEC_TOOL_ENTRY *NewGuidTool;

  FirstGuidTool = NULL;
  LastGuidTool  = NULL;

  while (TRUE) {
    NextLine = ReadMemoryFileLine (InputFile);
    if (NextLine == NULL) {
      break;
    }

    Status = StripInfDscStringInPlace (NextLine);
    if (EFI_ERROR (Status)) {
      free (NextLine);
      break;
    }

    if (NextLine[0] == '\0') {
      free (NextLine);
      continue;
    }

    Tool = SplitStringByWhitespace (NextLine);
    if ((Tool != NULL) &&
        (Tool->Count == 3)
       ) {
      Status = StringToGuid (Tool->Strings[0], &Guid);
      if (!EFI_ERROR (Status)) {
        NewGuidTool = malloc (sizeof (GUID_SEC_TOOL_ENTRY));
        if (NewGuidTool != NULL) {
          memcpy (&(NewGuidTool->Guid), &Guid, sizeof (Guid));
          NewGuidTool->Name = CloneString(Tool->Strings[1]);
          NewGuidTool->Path = CloneString(Tool->Strings[2]);
          NewGuidTool->Next = NULL;

          if (FirstGuidTool == NULL) {
            FirstGuidTool = NewGuidTool;
          } else {
            LastGuidTool->Next = NewGuidTool;
          }
          LastGuidTool = NewGuidTool;
        }
      }
    }

    if (Tool != NULL) {
      FreeStringList (Tool);
    }
    free (NextLine);
  }

  return FirstGuidTool;
}
Esempio n. 10
0
glob_t *I_StartMultiGlob(const char *directory, int flags,
                         const char *glob, ...)
{
    char **globs;
    int num_globs;
    glob_t *result;
    va_list args;

    globs = malloc(sizeof(char *));
    if (globs == NULL)
    {
        return NULL;
    }
    globs[0] = M_StringDuplicate(glob);
    num_globs = 1;

    va_start(args, glob);
    for (;;)
    {
        const char *arg = va_arg(args, const char *);
        char **new_globs;

        if (arg == NULL)
        {
            break;
        }

        new_globs = realloc(globs, sizeof(char *) * (num_globs + 1));
        if (new_globs == NULL)
        {
            FreeStringList(globs, num_globs);
        }
        globs = new_globs;
        globs[num_globs] = M_StringDuplicate(arg);
        ++num_globs;
    }
    va_end(args);

    result = malloc(sizeof(glob_t));
    if (result == NULL)
    {
        FreeStringList(globs, num_globs);
        return NULL;
    }

    result->dir = opendir(directory);
    if (result->dir == NULL)
    {
        FreeStringList(globs, num_globs);
        free(result);
        return NULL;
    }

    result->directory = M_StringDuplicate(directory);
    result->globs = globs;
    result->num_globs = num_globs;
    result->flags = flags;
    result->last_filename = NULL;
    result->filenames = NULL;
    result->filenames_len = 0;
    result->next_index = -1;
    return result;
}
Esempio n. 11
0
void
LoaderFreeDirList(char **list)
{
    FreeStringList(list);
}
Esempio n. 12
0
static void
FreePathList(char **pathlist)
{
    if (pathlist && pathlist != defaultPathList)
        FreeStringList(pathlist);
}
Esempio n. 13
0
/*
 * private static bool StartProcess(String filename, String arguments,
 *									String workingDir,
 *									String[] argv, int flags,
 *									int windowStyle, String[] envVars,
 *									String verb, IntPtr errorDialogParent,
 *									out IntPtr processHandle,
 *									out int processID,
 *									out IntPtr stdinHandle,
 *									out IntPtr stdoutHandle,
 *									out IntPtr stderrHandle);
 */
ILBool _IL_Process_StartProcess(ILExecThread *_thread,
								ILString *filename,
								ILString *arguments,
								ILString *workingDir,
								System_Array *argv,
								ILInt32 flags,
								ILInt32 windowStyle,
								System_Array *envVars,
								ILString *verb,
								ILNativeInt errorDialogParent,
								ILNativeInt *processHandle,
								ILInt32 *processID,
								ILNativeInt *stdinHandle,
								ILNativeInt *stdoutHandle,
								ILNativeInt *stderrHandle)
{
#ifdef IL_WIN32_PLATFORM

#ifdef IL_WIN32_CYGWIN
	#define	GET_OSF(fd)		((HANDLE)(get_osfhandle((fd))))
	#define	MAKE_PIPE(fds)	(pipe((fds)))
#else
	#define	GET_OSF(fd)		((HANDLE)(_get_osfhandle((fd))))
	#define	MAKE_PIPE(fds)	(_pipe((fds), 0, _O_BINARY))
#endif

	const char *fname;
	const char *workdir = 0;
	char *args;
	STARTUPINFO startupInfo;
	PROCESS_INFORMATION processInfo;
	char *env = 0;
	ILBool result;
	int pipefds[2];
	int cleanups[8];
	int numCleanups = 0;
	int closeAfterFork[8];
	int numCloseAfterFork = 0;
	int index;
#if defined(HAVE_SYS_CYGWIN_H) && defined(HAVE_CYGWIN_CONV_TO_WIN32_PATH)
	char cygFname[4096];
	char cygWorkdir[4096];
#endif

	/* Clear errno, because we will check for it when something fails */
	ILSysIOSetErrno(0);

	/* Convert the parameters into something that the OS can understand */
	fname = ILStringToAnsi(_thread, filename);
	if(!fname)
	{
		return 0;
	}

#if defined(HAVE_SYS_CYGWIN_H) && defined(HAVE_CYGWIN_CONV_TO_WIN32_PATH)
	/* Use the Cygwin-supplied function to convert the path
	   that CreateProcess() will understand */
	if(cygwin_conv_to_win32_path(fname, cygFname) == 0)
	{
		fname = cygFname;
	}
#endif

	if(((System_String *) workingDir)->length)
	{
		workdir = ILStringToAnsi(_thread, workingDir);
		if(!workdir)
		{
			return 0;
		}
#if defined(HAVE_SYS_CYGWIN_H) && defined(HAVE_CYGWIN_CONV_TO_WIN32_PATH)
		/* Use convert workdir for CreateProcess() under cygwin */
		if(cygwin_conv_to_win32_path(workdir, cygWorkdir) == 0)
		{
			workdir = cygWorkdir;
		}
#endif
	}
	args = ILStringToAnsi(_thread, arguments);
	if(!args)
	{
		return 0;
	}
	ILMemZero(&startupInfo, sizeof(startupInfo));
	startupInfo.cb = sizeof(STARTUPINFO);
	startupInfo.dwFlags = STARTF_USESHOWWINDOW;
	startupInfo.wShowWindow = (WORD)windowStyle;

	/* Redirect stdin, stdout, and stderr if necessary */
	*stdinHandle = (ILNativeInt)(ILSysIOHandle_Invalid);
	*stdoutHandle = (ILNativeInt)(ILSysIOHandle_Invalid);
	*stderrHandle = (ILNativeInt)(ILSysIOHandle_Invalid);
	if((flags & (ProcessStart_RedirectStdin |
				 ProcessStart_RedirectStdout |
				 ProcessStart_RedirectStderr)) != 0)
	{
		startupInfo.dwFlags |= STARTF_USESTDHANDLES;
		if((flags & ProcessStart_RedirectStdin) != 0)
		{
			MAKE_PIPE(pipefds);
			*stdinHandle = (ILNativeInt)(pipefds[1]);
			SetHandleInformation(GET_OSF(pipefds[1]),
								 HANDLE_FLAG_INHERIT, 0);
			startupInfo.hStdInput = GET_OSF(pipefds[0]);
			cleanups[numCleanups++] = pipefds[0];
			cleanups[numCleanups++] = pipefds[1];
			closeAfterFork[numCloseAfterFork++] = pipefds[0];
		}
		else
		{
			startupInfo.hStdInput = GET_OSF(0);
		}
		if((flags & ProcessStart_RedirectStdout) != 0)
		{
			MAKE_PIPE(pipefds);
			*stdoutHandle = (ILNativeInt)(pipefds[0]);
			SetHandleInformation(GET_OSF(pipefds[0]),
								 HANDLE_FLAG_INHERIT, 0);
			startupInfo.hStdOutput = GET_OSF(pipefds[1]);
			cleanups[numCleanups++] = pipefds[0];
			cleanups[numCleanups++] = pipefds[1];
			closeAfterFork[numCloseAfterFork++] = pipefds[1];
		}
		else
		{
			startupInfo.hStdOutput = GET_OSF(1);
		}
		if((flags & ProcessStart_RedirectStderr) != 0)
		{
			MAKE_PIPE(pipefds);
			*stderrHandle = (ILNativeInt)(pipefds[0]);
			SetHandleInformation(GET_OSF(pipefds[0]),
								 HANDLE_FLAG_INHERIT, 0);
			startupInfo.hStdError = GET_OSF(pipefds[1]);
			cleanups[numCleanups++] = pipefds[0];
			cleanups[numCleanups++] = pipefds[1];
			closeAfterFork[numCloseAfterFork++] = pipefds[1];
		}
		else
		{
			startupInfo.hStdError = GET_OSF(2);
		}
	}

	/* TODO: shell execution, environment variables, and ExecOverTop */

	/* Launch the process */
	*processID = -1;
	*processHandle = 0;
	result = 0;
	if(CreateProcess(fname, args, NULL, NULL, TRUE, 0, env, workdir,
					 &startupInfo, &processInfo))
	{
		*processHandle = (ILNativeInt)(processInfo.hProcess);
		*processID = (ILInt32)(processInfo.dwProcessId);
		result = 1;
	}
	else
	{
		/* TODO: it could be useful to report error details using GetLastError().
		   We can't do ILSysIOSetErrno(GetLastError()), because errno is related
		   to IO function, while GetLastError() is windows-specific error code */
		ILSysIOSetErrno(ENOENT);
	}

	/* Clean up and exit */
	if(env)
	{
		ILFree(env);
	}
	if(result)
	{
		for(index = 0; index < numCloseAfterFork; ++index)
		{
			close(closeAfterFork[index]);
		}
	}
	else
	{
		for(index = 0; index < numCleanups; ++index)
		{
			close(cleanups[index]);
		}
	}
	return result;

#elif defined(HAVE_FORK) && defined(HAVE_EXECV) && (defined(HAVE_WAITPID) || defined(HAVE_WAIT))
#define	IL_USING_FORK	1

	const char *fname;
	const char *workdir = 0;
	char **args;
	char **newEnviron = 0;
	int varNum = 0;
	int stdinFds[2] = {-1, -1};
	int stdoutFds[2] = {-1, -1};
	int stderrFds[2] = {-1, -1};
	ILBool result = 0;
	int pid;
	ILInt32 argc;
	const char *ansi;
	int pipefds[2];
#define	FreeStringList(list,size)	\
		do { \
			if((list)) \
			{ \
				int __posn = (int)(size); \
				while(__posn > 0) \
				{ \
					--__posn; \
					ILFree((list)[__posn]); \
				} \
				ILFree((list)); \
			} \
		} while (0)

	/* Convert the parameters into something that the OS can understand */
	fname = ILStringToAnsi(_thread, filename);
	if(!fname)
	{
		return 0;
	}
	if(((System_String *) workingDir)->length)
	{
		workdir = ILStringToAnsi(_thread, workingDir);
		if(!workdir)
		{
			return 0;
		}
	}
	args = (char **)ILCalloc(ArrayLength(argv) + 1, sizeof(char *));
	if(!args)
	{
		ILExecThreadThrowOutOfMemory(_thread);
		return 0;
	}
	argc = 0;
	while(argc < ArrayLength(argv))
	{
		ansi = ILStringToAnsi
			(_thread, ((ILString **)ArrayToBuffer(argv))[argc]);
		if(!ansi)
		{
			FreeStringList(args, argc);
			return 0;
		}
		args[argc] = (char *)ILMalloc(strlen(ansi) + 1);
		if(!(args[argc]))
		{
			FreeStringList(args, argc);
			return 0;
		}
		strcpy(args[argc], ansi);
		++argc;
	}
	args[argc] = 0;

	/* Convert the environment */
	if(envVars)
	{
		newEnviron = (char **)ILCalloc(ArrayLength(envVars) + 1, sizeof(char *));
		if(!newEnviron)
		{
			ILExecThreadThrowOutOfMemory(_thread);
			FreeStringList(args, argc);
			return 0;
		}
		while(varNum < (int)(ArrayLength(envVars)))
		{
			ansi = ILStringToAnsi
				(_thread, ((ILString **)ArrayToBuffer(envVars))[varNum]);
			if(!ansi)
			{
				FreeStringList(args, argc);
				FreeStringList(newEnviron, varNum);
				return 0;
			}
			newEnviron[varNum] = (char *)ILMalloc(strlen(ansi) + 1);
			if(!(newEnviron[varNum]))
			{
				FreeStringList(args, argc);
				FreeStringList(newEnviron, varNum);
				return 0;
			}
			strcpy(newEnviron[varNum], ansi);
			++varNum;
		}
		newEnviron[varNum] = 0;
	}

	/* Redirect stdin, stdout, and stderr as necessary */
	*stdinHandle = (ILNativeInt)(ILSysIOHandle_Invalid);
	*stdoutHandle = (ILNativeInt)(ILSysIOHandle_Invalid);
	*stderrHandle = (ILNativeInt)(ILSysIOHandle_Invalid);
	if((flags & ProcessStart_RedirectStdin) != 0)
	{
		if(pipe(stdinFds) < 0)
		{
			return 0;
		}
	#if HAVE_FCNTL
		fcntl(stdinFds[1], F_SETFD, 1);
	#endif
		*stdinHandle = (ILNativeInt)(stdinFds[1]);
	}
	if((flags & ProcessStart_RedirectStdout) != 0)
	{
		if(pipe(stdoutFds) < 0)
		{
			if((flags & ProcessStart_RedirectStdin) != 0)
			{
				close(stdinFds[0]);
				close(stdinFds[1]);
			}
			return 0;
		}
	#if HAVE_FCNTL
		fcntl(stdoutFds[0], F_SETFD, 1);
	#endif
		*stdoutHandle = (ILNativeInt)(stdoutFds[0]);
	}
	if((flags & ProcessStart_RedirectStderr) != 0)
	{
		if(pipe(stderrFds) < 0)
		{
			if((flags & ProcessStart_RedirectStdin) != 0)
			{
				close(stdinFds[0]);
				close(stdinFds[1]);
			}
			if((flags & ProcessStart_RedirectStdout) != 0)
			{
				close(stdoutFds[0]);
				close(stdoutFds[1]);
			}
			return 0;
		}
	#if HAVE_FCNTL
		fcntl(stderrFds[0], F_SETFD, 1);
	#endif
		*stderrHandle = (ILNativeInt)(stderrFds[0]);
	}

	/* Open the pipe for returning errno */
	if(pipe(pipefds) < 0)
	{
		return 0;
	}
	
	/* Fork and execute the process */
	*processID = -1;
	*processHandle = 0;
	pid = fork();
	if(pid == 0)
	{
		/* We are in the child process */
		if((flags & ProcessStart_RedirectStdin) != 0)
		{
			dup2(stdinFds[0], 0);
			close(stdinFds[0]);
		}
		if((flags & ProcessStart_RedirectStdout) != 0)
		{
			dup2(stdoutFds[1], 1);
			close(stdoutFds[1]);
		}
		if((flags & ProcessStart_RedirectStderr) != 0)
		{
			dup2(stderrFds[1], 2);
			close(stderrFds[1]);
		}
		if(newEnviron)
		{
			extern char **environ;
			environ = newEnviron;
		}
		close(pipefds[0]);
		
	#ifdef HAVE_FCNTL
		fcntl(pipefds[1],F_SETFD,1);
	#endif
		if(workdir)
		{
			if(ILChangeDir(workdir) != IL_ERRNO_Success)
			{
				/* Send errno to parent process */
				write(pipefds[1],&errno, sizeof(errno));
				exit(1);
			}
		}

		execvp(fname, args);
		write(pipefds[1],&errno, sizeof(errno));
		exit(1);
	}
	else if(pid > 0)
	{
		/* We are in the parent process */
		if((flags & ProcessStart_RedirectStdin) != 0)
		{
			close(stdinFds[0]);
		}
		if((flags & ProcessStart_RedirectStdout) != 0)
		{
			close(stdoutFds[1]);
		}
		if((flags & ProcessStart_RedirectStderr) != 0)
		{
			close(stderrFds[1]);
		}
		*processID = (ILInt32)pid;
		close(pipefds[1]);
		errno = 0;
		read(pipefds[0],&errno,sizeof(errno));
		close(pipefds[0]);
		result = (errno == 0);
	}
	else
	{
		/* An error occurred during the fork */
		if((flags & ProcessStart_RedirectStdin) != 0)
		{
			close(stdinFds[0]);
			close(stdinFds[1]);
		}
		if((flags & ProcessStart_RedirectStdout) != 0)
		{
			close(stdoutFds[0]);
			close(stdoutFds[1]);
		}
		if((flags & ProcessStart_RedirectStderr) != 0)
		{
			close(stderrFds[0]);
			close(stderrFds[1]);
		}
		close(pipefds[0]);
		close(pipefds[1]);
	}

	/* Clean up and exit */
	FreeStringList(args, argc);
	FreeStringList(newEnviron, varNum);
	return result;

#else
	/* Don't know how to spawn processes on this platform */
	return 0;
#endif
}
 //Teardown
 ~EnchantDictFreeStringList_TestFixture()
 {
     FreeStringList(_string_list);
     FreeStringList(_pwl_string_list);
 }