Import libtu instead of using submodules
[notion/jeffpc.git] / libtu / prefix.c
blob676ae2e0790a70e5cd373a2265441e9f29598c10
1 /*
2 * libtu/prefix.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * You may distribute and modify this library under the terms of either
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
8 */
10 #include <string.h>
11 #include "misc.h"
12 #include "locale.h"
13 #include "output.h"
15 static char *the_prefix=NULL;
17 void prefix_set(const char *binloc, const char *dflt)
19 int i=strlen(binloc);
20 int j=strlen(dflt);
22 if(binloc[0]!='/')
23 die(TR("This relocatable binary should be started with an absolute path."));
25 while(i>0 && j>0){
26 if(binloc[i-1]!=dflt[j-1])
27 break;
28 i--;
29 j--;
32 the_prefix=scopyn(binloc, i);
37 char *prefix_add(const char *s)
39 if(the_prefix==NULL)
40 return scopy(s);
41 else
42 return scat3(the_prefix, "/", s);
46 bool prefix_wrap_simple(bool (*fn)(const char *s), const char *s)
48 bool ret=FALSE;
50 if(the_prefix==NULL){
51 ret=fn(s);
52 }else{
53 char *s2=prefix_add(s);
54 if(s2!=NULL){
55 ret=fn(s2);
56 free(s2);
60 return ret;