File: prefix.c

package info (click to toggle)
notion 4.0.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,676 kB
  • sloc: ansic: 47,508; sh: 2,096; makefile: 603; perl: 270
file content (61 lines) | stat: -rw-r--r-- 1,114 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * libtu/prefix.c
 *
 * Copyright (c) Tuomo Valkonen 1999-2007.
 *
 * You may distribute and modify this library under the terms of either
 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
 */

#include <string.h>
#include "misc.h"
#include "locale.h"
#include "output.h"

static char *the_prefix=NULL;

void prefix_set(const char *binloc, const char *dflt)
{
    int i=strlen(binloc);
    int j=strlen(dflt);

    if(binloc[0]!='/')
        die(TR("This relocatable binary should be started with an absolute path."));

    while(i>0 && j>0){
        if(binloc[i-1]!=dflt[j-1])
            break;
        i--;
        j--;
    }

    the_prefix=scopyn(binloc, i);

}


char *prefix_add(const char *s)
{
    if(the_prefix==NULL)
        return scopy(s);
    else
        return scat3(the_prefix, "/", s);
}


bool prefix_wrap_simple(bool (*fn)(const char *s), const char *s)
{
    bool ret=FALSE;

    if(the_prefix==NULL){
        ret=fn(s);
    }else{
        char *s2=prefix_add(s);
        if(s2!=NULL){
            ret=fn(s2);
            free(s2);
        }
    }

    return ret;
}