summaryrefslogtreecommitdiff
path: root/libc/debian/crle.c
blob: 9f1997ec0ffaf551fb8d80cef714d8fa98bd8e26 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* 
Copyright: 2012, Igor Pashev <pashev.igor@gmail.com>

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
                   Version 2, December 2004 

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> 

Everyone is permitted to copy and distribute verbatim or modified 
copies of this license document, and changing it is allowed as long 
as the name is changed. 

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 

 0. You just DO WHAT THE FUCK YOU WANT TO. 
*/

/*
 * Wrapper for real crle(1).
 *
 * Runtime linker uses binary config file, and
 * 32- and 64-bit versions of the linker use different
 * config files. To make changes to those files one must use
 * crle(1) of corresponding bitness.
 *
 * Since we cannot have two or more files named '/usr/bin/crle',
 * we create this wrapper, which will dispatch to corresponding
 * real program residing under /usr/lib/<multiarch>/ and under
 * /usr/lib32 (on 64-bit systems).
 *
 * For example, let's assume we are on amd64 system:
 * /usr/bin/crle without -64 or -32 options will execute "native" crle
 * (/usr/lib/x86_64-illumos/crle); with -32 option - /usr/lib32/crle;
 * option -64 is noop.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

const char crle64[] = DEB_USRLIBDIR_64 "/crle";
const char crle32[] = DEB_USRLIBDIR_32 "/crle";
char *help[] = { "crle", "-h" };

#if DEB_HOST_ARCH_BITS == 64
#define crle crle64
#elif DEB_HOST_ARCH_BITS == 32
#define crle crle32
#else
#error DEB_HOST_ARCH_BITS is not set or has a wrong value
#endif

static void
myexec (const char *path, char **argv)
{
  int rc;
  rc = execv (path, argv);
  perror (path);
  exit (rc);
}

int
main (int argc, char **argv)
{
  int i;
  int use_help = 0;
  int use_64 = 0;
  int use_32 = 0;

  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] == '-' && argv[i][1] == 'h')
        use_help++;
      else if (strcmp ("-64", argv[i]) == 0)
        use_64++;
      else if (strcmp ("-32", argv[i]) == 0)
        use_32++;
    }

  if (use_help)
    myexec (crle, help);

  if (!use_64 && !use_32)
    myexec (crle, argv);

  if (use_64 && !use_32)
    myexec (crle64, argv);

  if (use_32 && !use_64)
    myexec (crle32, argv);

  fprintf (stderr, "Options -32 and -64 cannot be used together\n");
  return EXIT_FAILURE;
}