]> git.pld-linux.org Git - packages/glibc.git/blob - glibc-LD-path.c
- nuke sprintf family, to be used with diet
[packages/glibc.git] / glibc-LD-path.c
1 /*
2  * Copyright (c) 2004 Elan Ruusamäe <glen@pld-linux.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *        This product includes software developed by Elan Ruusamäe
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ELAN RUUSAMÄE AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33 /*
34  * Usage
35  * ~~~~~
36  *
37  * This simple program is aimed to be used as a workaround when installing over
38  * glibc which has placed glibc.so into /lib/i686.
39  *
40  * For example, in glibc.spec:
41  *
42  * %post -p /sbin/postshell
43  * /sbin/glibc-postrm /%{_lib}/i686
44  *
45  * Patches and bugreports are welcome, direct them to Elan Ruusamäe
46  * <glen@pld-linux.org>.
47  */
48
49
50 #include <sys/stat.h>
51 #include <unistd.h>
52 #include <stdio.h>
53 #include <errno.h>
54 #include <string.h>
55 #include <stdlib.h>
56
57 #define error(msg) write(2, msg, strlen(msg))
58 #define warn(msg) write(2, msg, strlen(msg))
59
60 int main (int argc, char *argv[])
61 {
62 struct stat st;
63 int i, rv = 0;
64
65         if (argc == 1) {
66                 error("This program is intended to be used by glibc postinstall stage.\n");
67                 exit(1);
68         }
69
70         for (i = 1; i < argc; i++) {
71                 char *path = argv[i];
72
73                 if (stat(path, &st) == -1) {
74                         // doesn't exist. good. next please.
75                         if (errno == ENOENT) {
76                                 continue;
77                         }
78                         perror("stat");
79                         exit(1);
80                 }
81
82                 if (S_ISDIR(st.st_mode)) {
83                         int l = strlen(path);
84                         char p[l + sizeof(".rpmsave") + 1];
85
86                         strcpy(p, path);
87                         strcpy(p + l, ".rpmsave");
88                         warn("Renaming "); warn(path); warn(" to "); warn(p); warn("\n");
89                         if (rename(path, p) == -1) {
90                                 perror("rename");
91                                 rv = 1;
92                         }
93                 }
94         }
95
96         exit(rv);
97 }
This page took 0.030453 seconds and 4 git commands to generate.