2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
28 #include <WINNT\afsreg.h>
30 long fs_ExtractDriveLetter(char *inPathp, char *outPathp)
32 if (inPathp[0] != 0 && inPathp[1] == ':') {
33 /* there is a drive letter */
34 *outPathp++ = *inPathp++;
35 *outPathp++ = *inPathp++;
43 /* strip the drive letter from a component */
44 long fs_StripDriveLetter(char *inPathp, char *outPathp, long outSize)
46 char tempBuffer[1000];
47 strcpy(tempBuffer, inPathp);
48 if (tempBuffer[0] != 0 && tempBuffer[1] == ':') {
49 /* drive letter present */
50 strcpy(outPathp, tempBuffer+2);
53 /* no drive letter present */
54 strcpy(outPathp, tempBuffer);
59 /* take a path with a drive letter, possibly relative, and return a full path
60 * without the drive letter. This is the full path relative to the working
61 * dir for that drive letter. The input and output paths can be the same.
63 long fs_GetFullPath(char *pathp, char *outPathp, long outSize)
73 if (pathp[0] != 0 && pathp[1] == ':') {
74 /* there's a drive letter there */
83 if (*firstp == '\\' || *firstp == '/') {
84 /* already an absolute pathname, just copy it back */
85 strcpy(outPathp, firstp);
89 GetCurrentDirectory(sizeof(origPath), origPath);
92 if (pathHasDrive && (*pathp & ~0x20) != (origPath[0] & ~0x20)) {
93 /* a drive has been specified and it isn't our current drive.
94 * to get path, switch to it first. Must case-fold drive letters
95 * for user convenience.
101 if (!SetCurrentDirectory(newPath)) {
102 code = GetLastError();
107 /* now get the absolute path to the current wdir in this drive */
108 GetCurrentDirectory(sizeof(tpath), tpath);
109 strcpy(outPathp, tpath+2); /* skip drive letter */
110 /* if there is a non-null name after the drive, append it */
112 strcat(outPathp, "\\");
113 strcat(outPathp, firstp);
116 /* finally, if necessary, switch back to our home drive letter */
118 SetCurrentDirectory(origPath);
124 /* is this a digit or a digit-like thing? */
125 static int ismeta(int abase, int ac) {
126 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
127 if (ac >= '0' && ac <= '7') return 1;
128 if (abase <= 8) return 0;
129 if (ac >= '8' && ac <= '9') return 1;
130 if (abase <= 10) return 0;
131 if (ac >= 'a' && ac <= 'f') return 1;
132 if (ac >= 'A' && ac <= 'F') return 1;
136 /* given that this is a digit or a digit-like thing, compute its value */
137 static int getmeta(int ac) {
138 if (ac >= '0' && ac <= '9') return ac - '0';
139 if (ac >= 'a' && ac <= 'f') return ac - 'a' + 10;
140 if (ac >= 'A' && ac <= 'F') return ac - 'A' + 10;
144 afs_int32 util_GetInt32 (char *as, afs_int32 *aval)
151 total = 0; /* initialize things */
154 /* skip over leading spaces */
156 if (tc != ' ' && tc != '\t') break;
162 as++; /* skip over character */
165 /* compute the base */
168 if (*as == 'x' || *as == 'X') {
176 /* compute the # itself */
178 if (!ismeta(base, tc)) return -1;
180 total += getmeta(tc);
184 if (negative) *aval = -total;
189 char *cm_mount_root="afs";
190 char *cm_slash_mount_root="/afs";
191 char *cm_back_slash_mount_root="\\afs";
193 void fs_utils_InitMountRoot()
196 char mountRoot[MAX_PATH+1];
197 char *pmount=mountRoot;
198 DWORD len=sizeof(mountRoot)-1;
199 printf("int mountroot \n");
200 if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY, 0,
201 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey)!= ERROR_SUCCESS)
202 || (RegQueryValueEx(parmKey, "Mountroot", NULL, NULL,(LPBYTE)(mountRoot), &len)!= ERROR_SUCCESS)
203 || (len==sizeof(mountRoot)-1)
205 strcpy(mountRoot, "\\afs");
206 RegCloseKey(parmKey);
207 mountRoot[len]=0; /*safety see ms-help://MS.MSDNQTR.2002OCT.1033/sysinfo/base/regqueryvalueex.htm*/
208 cm_mount_root=malloc(len+1);
209 cm_slash_mount_root=malloc(len+2);
210 cm_back_slash_mount_root=malloc(len+2);
211 if ((*pmount=='/') || (*pmount='\\'))
213 strcpy(cm_mount_root,pmount);
214 strcpy(cm_slash_mount_root+1,pmount);
215 cm_slash_mount_root[0]='/';
216 strcpy(cm_back_slash_mount_root+1,pmount);
217 cm_back_slash_mount_root[0]='\\';