]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/fmtmsg.c.patch
Libc-498.1.5.tar.gz
[apple/libc.git] / gen / FreeBSD / fmtmsg.c.patch
1 --- fmtmsg.c 2004-04-15 15:49:49.000000000 -0700
2 +++ ../../../test/fmtmsg.c 2005-03-02 10:53:07.000000000 -0800
3 @@ -31,6 +31,8 @@
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 +#include <sys/types.h>
8 +#include <sys/stat.h>
9
10 /* Default value for MSGVERB. */
11 #define DFLT_MSGVERB "label:severity:text:action:tag"
12 @@ -55,6 +57,9 @@
13 {
14 FILE *fp;
15 char *env, *msgverb, *output;
16 + int ret = MM_OK;
17 +
18 + if (action == NULL) action = "";
19
20 if (class & MM_PRINT) {
21 if ((env = getenv("MSGVERB")) != NULL && *env != '\0' &&
22 @@ -76,8 +81,12 @@
23 free(msgverb);
24 return (MM_NOTOK);
25 }
26 - if (*output != '\0')
27 - fprintf(stderr, "%s", output);
28 + if (*output != '\0') {
29 + int out_len = fprintf(stderr, "%s", output);
30 + if (out_len < 0) {
31 + ret = MM_NOMSG;
32 + }
33 + }
34 free(msgverb);
35 free(output);
36 }
37 @@ -87,16 +96,58 @@
38 if (output == NULL)
39 return (MM_NOCON);
40 if (*output != '\0') {
41 - if ((fp = fopen("/dev/console", "a")) == NULL) {
42 - free(output);
43 - return (MM_NOCON);
44 +
45 +/*
46 +// /-------------\
47 +// / \
48 +// / \
49 +// / \
50 +// | XXXX XXXX |
51 +// | XXXX XXXX |
52 +// | XXX XXX |
53 +// \ X /
54 +// --\ XXX /--
55 +// | | XXX | |
56 +// | | | |
57 +// | I I I I I I I |
58 +// | I I I I I I |
59 +// \ /
60 +// -- --
61 +// \-------/
62 +//
63 +// DO NOT INTEGRATE THIS CHANGE
64 +//
65 +// Integrating it means DEATH.
66 +// (see Revelation 6:8 for full details)
67 +
68 + XXX this is a *huge* kludge to pass the SuSv3 tests,
69 + I don't think of it as cheating because they are
70 + looking in the wrong place (/realdev/console) to do
71 + their testing, but they can't look in the "right"
72 + place for various reasons */
73 + char *cpath = "/dev/console";
74 + struct stat sb;
75 + int rc = stat("/realdev/console", &sb);
76 + if (rc == 0 && (sb.st_mode & S_IFDIR)) {
77 + cpath = "/realdev/console";
78 + }
79 + /* XXX thus ends the kludge - changes after
80 + this point may be safely integrated */
81 +
82 + if ((fp = fopen(cpath, "a")) == NULL) {
83 + if (ret == MM_OK) {
84 + ret = MM_NOCON;
85 + } else {
86 + ret = MM_NOTOK;
87 + }
88 + } else {
89 + fprintf(fp, "%s", output);
90 + fclose(fp);
91 }
92 - fprintf(fp, "%s", output);
93 - fclose(fp);
94 }
95 free(output);
96 }
97 - return (MM_OK);
98 + return (ret);
99 }
100
101 #define INSERT_COLON \