Пример #1
0
unsigned long _System
_DLL_InitTerm (unsigned long hModule, unsigned long ulFlag)
{
  static char location[CCHMAXPATH];

  switch (ulFlag)
    {
      case 0:
        if (_CRT_init () == -1)
          return 0;

        __ctordtorInit();

        /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
           for specification of DosQueryModuleName(). */
        if (DosQueryModuleName (hModule, sizeof (location), location))
          return 0;

        _fnslashify (location);
        shared_library_fullname = strdup (location);
        break;

      case 1:
        __ctordtorTerm();

        _CRT_term ();
        break;
    }

  return 1;
}
Пример #2
0
/*
 * Convert backslashes of environmental variables to forward slahes.
 * A backslash may be used as an escaped character when doing 'echo'.
 * This leads to an unexpected behavior.
 */
static void
env_slashify(void)
{
	/*
	 * PATH and TMPDIR are used by OS/2 as well. That is, they may
	 * have backslashes as a directory separator.
	 * BEGINLIBPATH and ENDLIBPATH are special variables on OS/2.
	 */
	const char *var_list[] = {
		"PATH",
		"TMPDIR",
		"BEGINLIBPATH",
		"ENDLIBPATH",
		NULL
	};
	const char **var;
	char *value;

	for (var = var_list; *var; var++) {
		value = getenv(*var);

		if (value)
			_fnslashify(value);
	}
}
Пример #3
0
char *get_path(const char *filename){
	char *homedir;
	char *buff;
#ifdef __MINGW32__
	static char *config_dir = "/mplayer";
#else
	static char *config_dir = "/.mplayer";
#endif
	int len;
#ifdef CONFIG_MACOSX_BUNDLE
	struct stat dummy;
	CFIndex maxlen=256;
	CFURLRef res_url_ref=NULL;
	CFURLRef bdl_url_ref=NULL;
	char *res_url_path = NULL;
	char *bdl_url_path = NULL;
#endif

	if ((homedir = getenv("MPLAYER_HOME")) != NULL)
		config_dir = "";
	else if ((homedir = getenv("HOME")) == NULL)
#if defined(__MINGW32__) || defined(__CYGWIN__)
	/* Hack to get fonts etc. loaded outside of Cygwin environment. */
	{
		int i,imax=0;
		char exedir[260];
		GetModuleFileNameA(NULL, exedir, 260);
		for (i=0; i< strlen(exedir); i++)
			if (exedir[i] =='\\')
				{exedir[i]='/'; imax=i;}
		exedir[imax]='\0';
		homedir = exedir;
	}
#elif defined(__OS2__)
    {
        PPIB ppib;
        char path[260];

        // Get process info blocks
        DosGetInfoBlocks(NULL, &ppib);

        // Get full path of the executable
        DosQueryModuleName(ppib->pib_hmte, sizeof( path ), path);

        // Truncate name part including last backslash
        *strrchr(path, '\\') = 0;

        // Convert backslash to slash
        _fnslashify(path);

        homedir = path;
    }
#else
	return NULL;
#endif
	len = strlen(homedir) + strlen(config_dir) + 1;
	if (filename == NULL) {
		if ((buff = malloc(len)) == NULL)
			return NULL;
		sprintf(buff, "%s%s", homedir, config_dir);
	} else {
		len += strlen(filename) + 1;
		if ((buff = malloc(len)) == NULL)
			return NULL;
		sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
	}

#ifdef CONFIG_MACOSX_BUNDLE
	if (stat(buff, &dummy)) {

		res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
		bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle());

		if (res_url_ref&&bdl_url_ref) {

			res_url_path=malloc(maxlen);
			bdl_url_path=malloc(maxlen);

			while (!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) {
				maxlen*=2;
				res_url_path=realloc(res_url_path, maxlen);
			}
			CFRelease(res_url_ref);

			while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) {
				maxlen*=2;
				bdl_url_path=realloc(bdl_url_path, maxlen);
			}
			CFRelease(bdl_url_ref);

			if (strcmp(res_url_path, bdl_url_path) == 0)
				res_url_path = NULL;
		}

		if (res_url_path&&filename) {
			if ((strlen(filename)+strlen(res_url_path)+2)>maxlen) {
				maxlen=strlen(filename)+strlen(res_url_path)+2;
			}
			free(buff);
			buff = malloc(maxlen);
			strcpy(buff, res_url_path);

			strcat(buff,"/");
			strcat(buff, filename);
		}
	}
#endif
	mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
	return buff;
}
Пример #4
0
/**
 * gimp_path_parse:
 * @path: A list of directories separated by #G_SEARCHPATH_SEPARATOR.
 * @max_paths: The maximum number of directories to return.
 * @check: #TRUE if you want the directories to be checked.
 * @check_failed: Returns a #GList of path elements for which the
 *                check failed. Each list element is guaranteed
 *		  to end with a #G_PATH_SEPARATOR.
 *
 * Returns: A #GList of all directories in @path. Each list element
 *	    is guaranteed to end with a #G_PATH_SEPARATOR.
 **/
GList *
gimp_path_parse (gchar     *path,
                 gint       max_paths,
                 gboolean   check,
                 GList    **check_failed)
{
    gchar  *home;
    gchar **patharray;
    GList  *list = NULL;
    GList  *fail_list = NULL;
    gint    i;

    struct stat filestat;
    gint        err = FALSE;

    if (!path || !*path || max_paths < 1 || max_paths > 256)
        return NULL;

    home = g_get_home_dir ();

    patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths);

    for (i = 0; i < max_paths; i++)
    {
        GString *dir;

        if (!patharray[i])
            break;

#ifndef G_OS_WIN32
        if (*patharray[i] == '~')
        {
            dir = g_string_new (home);
            g_string_append (dir, patharray[i] + 1);
        }
        else
#endif
        {
            dir = g_string_new (patharray[i]);
        }

#ifdef __EMX__
        _fnslashify (dir);
#endif

        if (check)
        {
            /*  check if directory exists  */
            err = stat (dir->str, &filestat);

            if (!err && S_ISDIR (filestat.st_mode))
            {
                if (dir->str[dir->len - 1] != G_DIR_SEPARATOR)
                    g_string_append_c (dir, G_DIR_SEPARATOR);
            }
        }

        if (!err)
            list = g_list_prepend (list, g_strdup (dir->str));
        else if (check_failed)
            fail_list = g_list_prepend (fail_list, g_strdup (dir->str));

        g_string_free (dir, TRUE);
    }

    g_strfreev (patharray);

    list = g_list_reverse (list);

    if (check && check_failed)
    {
        fail_list = g_list_reverse (fail_list);
        *check_failed = fail_list;
    }

    return list;
}