- Timestamp:
- Jan 21, 2008, 2:43:22 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/function.c
r1307 r1383 59 59 # endif 60 60 #endif 61 62 #ifdef __OS2__ 63 # define CONFIG_WITH_OS2_LIBPATH 1 64 #endif 65 #ifdef CONFIG_WITH_OS2_LIBPATH 66 # define INCL_BASE 67 # define INCL_ERRROS 68 # include <os2.h> 69 70 # define QHINF_EXEINFO 1 /* NE exeinfo. */ 71 # define QHINF_READRSRCTBL 2 /* Reads from the resource table. */ 72 # define QHINF_READFILE 3 /* Reads from the executable file. */ 73 # define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */ 74 # define QHINF_LIBPATH 5 /* Gets the entire libpath. */ 75 # define QHINF_FIXENTRY 6 /* NE only */ 76 # define QHINF_STE 7 /* NE only */ 77 # define QHINF_MAPSEL 8 /* NE only */ 78 extern APIRET APIENTRY DosQueryHeaderInfo(HMODULE hmod, ULONG ulIndex, PVOID pvBuffer, ULONG cbBuffer, ULONG ulSubFunction); 79 #endif /* CONFIG_WITH_OS2_LIBPATH */ 61 80 62 81 … … 3316 3335 #endif 3317 3336 3337 #ifdef CONFIG_WITH_OS2_LIBPATH 3338 /* Sets or gets the OS/2 libpath variables. 3339 3340 The first argument indicates which variable - BEGINLIBPATH, 3341 ENDLIBPATH, LIBPATHSTRICT or LIBPATH. 3342 3343 The second indicates whether this is a get (not present) or 3344 set (present) operation. When present it is the new value for 3345 the variable. */ 3346 static char * 3347 func_os2_libpath (char *o, char **argv, const char *funcname) 3348 { 3349 char buf[4096]; 3350 ULONG fVar; 3351 APIRET rc; 3352 3353 /* translate variable name (first arg) */ 3354 if (!strcmp (argv[0], "BEGINLIBPATH")) 3355 fVar = BEGIN_LIBPATH; 3356 else if (!strcmp (argv[0], "ENDLIBPATH")) 3357 fVar = END_LIBPATH; 3358 else if (!strcmp (argv[0], "LIBPATHSTRICT")) 3359 fVar = LIBPATHSTRICT; 3360 else if (!strcmp (argv[0], "LIBPATH")) 3361 fVar = 0; 3362 else 3363 { 3364 error (NILF, _("$(libpath): unknown variable `%s'"), argv[0]); 3365 return variable_buffer_output (o, "", 0); 3366 } 3367 3368 if (!argv[1]) 3369 { 3370 /* get the variable value. */ 3371 if (fVar != 0) 3372 { 3373 buf[0] = buf[1] = buf[2] = buf[3] = '\0'; 3374 rc = DosQueryExtLIBPATH (psz, fVar); 3375 } 3376 else 3377 rc = DosQueryHeaderInfo (NULLHANDLE, 0, buf, sizeof(buf), QHINF_LIBPATH); 3378 if (rc != NO_ERROR) 3379 { 3380 error (NILF, _("$(libpath): failed to query `%s', rc=%d"), argv[0], rc); 3381 return variable_buffer_output (o, "", 0); 3382 } 3383 o = variable_buffer_output (o, buf, strlen (buf)); 3384 } 3385 else 3386 { 3387 /* set the variable value. */ 3388 size_t len; 3389 size_t len_max = sizeof (buf) < 2048 ? sizeof (buf) : 2048; 3390 const char *val; 3391 const char *end; 3392 3393 if (fVar == 0) 3394 { 3395 error (NILF, _("$(libpath): LIBPATH is read-only")); 3396 return variable_buffer_output (o, "", 0); 3397 } 3398 3399 /* strip leading and trailing spaces and check for max length. */ 3400 val = argv[1]; 3401 while (isspace (*val)) 3402 val++; 3403 end = strchr (val, '\0'); 3404 while (end > val && isspace (end[-1])) 3405 end--; 3406 3407 len = end - val; 3408 if (len >= len_max) 3409 { 3410 error (NILF, _("$(libpath): The new `%s' value is too long (%d bytes, max %d)"), 3411 argv[0], len, len_max); 3412 return variable_buffer_output (o, "", 0); 3413 } 3414 3415 /* make a stripped copy in low memory and try set it. */ 3416 memcpy (buf, val, len); 3417 buf[len] = '\0'; 3418 rc = DosSetExtLIBPATH (buf, fVar); 3419 if (rc != NO_ERROR) 3420 { 3421 error (NILF, _("$(libpath): failed to set `%s' to `%s', rc=%d"), argv[0], buf, rc); 3422 return variable_buffer_output (o, "", 0); 3423 } 3424 3425 o = variable_buffer_output (o, "", 0); 3426 } 3427 return o; 3428 } 3429 #endif /* CONFIG_WITH_OS2_LIBPATH */ 3318 3430 3319 3431 /* Lookup table for builtin functions. … … 3427 3539 { STRING_SIZE_TUPLE("nanots"), 0, 0, 0, func_nanots}, 3428 3540 #endif 3541 #ifdef CONFIG_WITH_OS2_LIBPATH 3542 { STRING_SIZE_TUPLE("libpath"), 1, 2, 1, func_os2_libpath}, 3543 #endif 3429 3544 #ifdef KMK_HELPERS 3430 3545 { STRING_SIZE_TUPLE("kb-src-tool"), 1, 1, 0, func_kbuild_source_tool},
Note:
See TracChangeset
for help on using the changeset viewer.