1 /* Utility and Unix shadow routines for XEmacs on Windows NT.
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 */
24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
25 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
26 /* Adapted to fpTeX 0.4 by Fabrice Popineau <Fabrice.Popineau@supelec.fr> */
30 #include <kpathsea/config.h>
31 #include <kpathsea/win32lib.h>
34 char initial_directory[MAXPATHLEN];
36 static char *cached_home_directory;
39 uncache_home_directory (void)
41 cached_home_directory = NULL; /* in some cases, this may cause the leaking
45 int output_home_warning = 0;
47 /* Returns the home directory, in external format */
49 get_home_directory (void)
52 if (cached_home_directory != NULL)
55 if ((cached_home_directory = getenv("HOME")) != NULL) {
57 /* In case it is %HOMEDRIVE%%HOMEPATH% */
58 if (ExpandEnvironmentStrings(cached_home_directory, q, sizeof(q)) == 0) {
60 cached_home_directory = NULL;
63 cached_home_directory = xstrdup(q);
69 char *homedrive, *homepath;
70 if ((homedrive = getenv("HOMEDRIVE")) != NULL &&
71 (homepath = getenv("HOMEPATH")) != NULL) {
72 cached_home_directory = concat(homedrive, homepath);
77 /* This method is the prefered one because even if it requires a more recent shell32.dll,
78 it does not need to call SHMalloc()->Free() */
80 /* This will probably give the wrong value */
83 HRESULT (WINAPI * p1)(HWND, LPSTR, int, BOOL);
84 HWND (WINAPI * p2)(void);
87 if (h = LoadLibrary("user32.dll")) {
88 if (p2 = GetProcAddress(h, "GetDesktopWindow"))
93 if (hwnd && (h = LoadLibrary("shell32.dll")) != NULL) {
94 if (p1 = GetProcAddress(h, "SHGetSpecialFolderPathA"))
95 if ((*p1)(hwnd, q, CSIDL_PERSONAL, TRUE)) {
96 cached_home_directory = xstrdup(q);
100 if (cached_home_directory) goto done;
103 if (output_home_warning) {
104 fprintf(stderr, "fpTeX has been unable to determine a good value for the user's $HOME\n"
105 " directory, and will be using the value:\n"
107 " This is probably incorrect.\n",
108 cached_home_directory
112 return cached_home_directory;