summaryrefslogtreecommitdiff
blob: d7fa3ea07bfcba6f609990ecc700bd43a0d27c09 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
diff --git a/common/printf.c b/common/printf.c
--- a/common/printf.c
+++ b/common/printf.c
@@ -21,6 +21,7 @@
    USA.  */
 
 #include "promlib.h"
+#include <stringops.h>
 
 /*
  * This part is rewritten by Igor Timkin <ivt@msu.su>. Than I
@@ -147,3 +148,88 @@ void prom_printf (char *fmt,...)
     vprintf (fmt, x1);
     va_end (x1);
 }
+
+static int sprintn (char *str, long long n, int b)
+{
+    static char prbuf[33];
+    register char *cp;
+    int count = 0;
+
+    if (b == 10 && n < 0) {
+	memset (str + count, '-', 1);
+	count++;
+	n = -n;
+    }
+    cp = prbuf;
+    do
+	*cp++ = "0123456789ABCDEF"[(unsigned int) (((unsigned long)n) % b)];
+    while ((n = ((unsigned long long)n) / b & 0x0FFFFFFFFFFFFFFFULL));
+    do {
+	memset (str + count, *--cp, 1);
+	count++;
+    } while (cp > prbuf);
+
+    return count;
+}
+
+int vsprintf (char *str, char *fmt, va_list adx)
+{
+    register int c;
+    char *s;
+    int count = 0;
+
+    for (;;) {
+	while ((c = *fmt++) != '%') {
+	    memset (str + count, c, 1);
+	    if (c == '\0') {
+		return count;
+	    }
+	}
+	c = *fmt++;
+	if (c == 'd' || c == 'o' || c == 'x' || c == 'X') {
+	    count += sprintn (str + count, (long long) va_arg (adx, unsigned),
+			     c == 'o' ? 8 : (c == 'd' ? 10 : 16));
+	} else if (c == 'c') {
+	    memset (str + count, va_arg (adx, unsigned), 1);
+	    count++;
+	} else if (c == 's') {
+	    if ((s = va_arg (adx, char *)) == NULL)
+		s = (char *)"(null)";
+	    while ((c = *s++)) {
+		memset (str + count, c, 1);
+		count++;
+	    }
+	} else if (c == 'l' || c == 'O') {
+	    count += sprintn (str + count, (long long) va_arg (adx, long), c == 'l' ? 10 : 8);
+	} else if (c == 'L') {
+	    int hex = 0;
+	    if (*fmt == 'x') {
+		fmt++;
+		hex = 1;
+	    }
+	    count += sprintn (str + count, (long long) va_arg (adx, long long), hex ? 16 : 10);
+	} else {
+	    /* This is basically what libc's printf does */
+	    memset (str + count, '%', 1);
+	    count++;
+	    memset (str + count, c, 1);
+	    count++;
+	}
+    }
+
+    return count;
+}
+
+/* Write formatted output into S, according to the format string FORMAT.  */
+/* VARARGS2 */
+int sprintf (char *s, const char *format, ...)
+{
+    va_list arg;
+    int done;
+
+    va_start (arg, format);
+    done = vsprintf (s, format, arg);
+    va_end (arg);
+
+    return done;
+}
diff --git a/second/Makefile b/second/Makefile
--- a/second/Makefile
+++ b/second/Makefile
@@ -58,13 +58,13 @@ fs/libfs.a: $(FS_OBJS)
 	$(AR) rc $@ $(FS_OBJS)
 
 second: $(OBJS) mark.o
-	$(LD) $(LDFLAGS_SMALL) -Bstatic -o second $(OBJS) -lext2fs mark.o
-	$(LD) $(LDFLAGS_LARGE) -Bstatic -o second2 $(OBJS) -lext2fs mark.o
+	$(LD) $(LDFLAGS_SMALL) -Bstatic -o second $(OBJS) -lext2fs mark.o `$(CC) -print-libgcc-file-name`
+	$(LD) $(LDFLAGS_LARGE) -Bstatic -o second2 $(OBJS) -lext2fs mark.o `$(CC) -print-libgcc-file-name`
 	$(NM) second | grep -v '*ABS*' | sort > second.map
 
 silotftp: $(OBJSNET) mark.o
-	$(LD) $(LDFLAGS_SMALL) -Bstatic -o silotftp $(OBJSNET) -lext2fs mark.o
-	$(LD) $(LDFLAGS_LARGE) -Bstatic -o silotftp2 $(OBJSNET) -lext2fs mark.o
+	$(LD) $(LDFLAGS_SMALL) -Bstatic -o silotftp $(OBJSNET) -lext2fs mark.o `$(CC) -print-libgcc-file-name`
+	$(LD) $(LDFLAGS_LARGE) -Bstatic -o silotftp2 $(OBJSNET) -lext2fs mark.o `$(CC) -print-libgcc-file-name`
 	$(NM) silotftp | grep -v '*ABS*' | sort > silotftp.map
 
 second.l: second