Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 75420 | Differences between
and this patch

Collapse All | Expand All

(-)wrapper-1.4.3.c (-1 / +86 lines)
Lines 25-26 Link Here
25
25
26
#define MAXNEWFLAGS 32
27
#define MAXFLAGLEN  127
28
26
struct wrapper_data {
29
struct wrapper_data {
Lines 32-33 struct wrapper_data { Link Here
32
	char *path;
35
	char *path;
36
	char newflags[MAXNEWFLAGS][MAXFLAGLEN + 1];
37
	unsigned newflagsCount;
33
};
38
};
Lines 251-252 static void modify_path(struct wrapper_d Link Here
251
256
257
#define lastOfStr(str, n) ((str) + strlen(str) - (n))
258
252
int main(int argc, char *argv[])
259
int main(int argc, char *argv[])
Lines 257-258 int main(int argc, char *argv[]) Link Here
257
	int result = 0;
264
	int result = 0;
265
	char **newargv = argv;
258
266
Lines 295-298 int main(int argc, char *argv[]) Link Here
295
303
304
	/* If this is g{cc,++}{32,64}, we need to add -m{32,64}
305
	 * otherwise  we need to add ${CFLAGS_${ABI}}
306
	 */
307
	if(!strcmp(lastOfStr(data->bin, 2), "32") ) {
308
		strcpy(data->newflags[data->newflagsCount], "-m32");
309
		data->bin[strlen(data->bin) - 2] = '\0';
310
		data->newflagsCount++;
311
	} else if (!strcmp(lastOfStr(data->bin, 2), "64") ) {
312
		data->bin[strlen(data->bin) - 2] = '\0';
313
		strcpy(data->newflags[data->newflagsCount], "-m64");
314
		data->newflagsCount++;
315
	} else if(getenv("ABI")) {
316
		char *envar = (char *)malloc(sizeof(char) * 
317
                                             (strlen("CFLAGS_") + strlen(getenv("ABI")) + 1 ));
318
		if(!envar)
319
			wrapper_exit("%s wrapper: out of memory\n", argv[0]);
320
321
		/* We use CFLAGS_${ABI} for gcc, g++, g77, etc as they are
322
		 * the same no matter which compiler we are using.
323
		 */
324
		sprintf(envar, "CFLAGS_%s", getenv("ABI"));
325
326
		if(getenv(envar)) {
327
			const char *newflagsStr = getenv(envar);
328
			unsigned s, f; /* start/finish of each flag. f points to
329
			                * the char AFTER the end (ie the space/\0
330
			                */
331
332
			/* Tokenize the flag list */
333
			for(s=0; s < strlen(newflagsStr); s=f+1) {
334
				/* Put s at the start of the next flag */
335
				while(newflagsStr[s] == ' ' || 
336
				      newflagsStr[s] == '\t')
337
					s++;
338
				if(s == strlen(newflagsStr))
339
					break;
340
341
				f = s + 1;
342
				while(newflagsStr[f] != ' ' && 
343
				      newflagsStr[f] != '\t' &&
344
				      newflagsStr[f] != '\0')
345
					f++;
346
347
				/* Detect overrun */
348
				if(MAXFLAGLEN < f - s || MAXNEWFLAGS == data->newflagsCount)
349
					wrapper_exit("%s wrapper: Exiting due to inadequate buffer space.  Preventing buffer overrun.\n", argv[0]);			
350
351
				strncpy(data->newflags[data->newflagsCount], newflagsStr + s, f - s);
352
				data->newflagsCount++;
353
			}
354
		}
355
356
		free(envar);
357
	}
358
359
	if(data->newflagsCount) {
360
		unsigned i;
361
362
		/* Make room for the original, new ones, and the NULL terminator */
363
		newargv = (char **)malloc(sizeof(char *) * (argc + data->newflagsCount + 1));
364
		if(!newargv)
365
			wrapper_exit("Unable to allocate enough memory for new argv[].");
366
367
		/* We just use the existing argv[i] as the start. */
368
		for(i=0; i < argc; i++) {
369
			newargv[i] = argv[i];
370
		}
371
372
		/* Now we want to append our newflags list. */
373
		for(; i < argc + data->newflagsCount; i++) {
374
			newargv[i] = data->newflags[i - argc];
375
		}
376
377
		/* And now cap it off... */
378
		newargv[i] = NULL;
379
	}
380
296
	/* Ok, do it ... */
381
	/* Ok, do it ... */
297
	if (execv(data->bin, argv) < 0)
382
	if (execv(data->bin, newargv) < 0)
298
		wrapper_exit("Could not run/locate \"%s\"\n", data->name);
383
		wrapper_exit("Could not run/locate \"%s\"\n", data->name);

Return to bug 75420