~ubuntu-branches/ubuntu/lucid/openssl/lucid-proposed

« back to all changes in this revision

Viewing changes to crypto/err/err_prn.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2009-06-13 18:15:46 UTC
  • mto: (11.1.5 squeeze)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090613181546-vbfntai3b009dl1u
Tags: upstream-0.9.8k
ImportĀ upstreamĀ versionĀ 0.9.8k

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
#ifndef OPENSSL_NO_FP_API
87
87
static int print_fp(const char *str, size_t len, void *fp)
88
88
        {
89
 
        BIO bio;
90
 
 
91
 
        BIO_set(&bio,BIO_s_file());
92
 
        BIO_set_fp(&bio,fp,BIO_NOCLOSE);
93
 
 
94
 
        return BIO_printf(&bio, "%s", str);
 
89
        return fwrite(str, 1, len, fp);
95
90
        }
96
91
void ERR_print_errors_fp(FILE *fp)
97
92
        {
99
94
        }
100
95
#endif
101
96
 
102
 
static int print_bio(const char *str, size_t len, void *bp)
103
 
        {
104
 
        return BIO_write((BIO *)bp, str, len);
105
 
        }
106
 
void ERR_print_errors(BIO *bp)
107
 
        {
108
 
        ERR_print_errors_cb(print_bio, bp);
109
 
        }
110
 
 
111
 
        
 
97
void ERR_error_string_n(unsigned long e, char *buf, size_t len)
 
98
        {
 
99
        char lsbuf[64], fsbuf[64], rsbuf[64];
 
100
        const char *ls,*fs,*rs;
 
101
        unsigned long l,f,r;
 
102
 
 
103
        l=ERR_GET_LIB(e);
 
104
        f=ERR_GET_FUNC(e);
 
105
        r=ERR_GET_REASON(e);
 
106
 
 
107
        ls=ERR_lib_error_string(e);
 
108
        fs=ERR_func_error_string(e);
 
109
        rs=ERR_reason_error_string(e);
 
110
 
 
111
        if (ls == NULL) 
 
112
                BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
 
113
        if (fs == NULL)
 
114
                BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
 
115
        if (rs == NULL)
 
116
                BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
 
117
 
 
118
        BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf, 
 
119
                fs?fs:fsbuf, rs?rs:rsbuf);
 
120
        if (strlen(buf) == len-1)
 
121
                {
 
122
                /* output may be truncated; make sure we always have 5 
 
123
                 * colon-separated fields, i.e. 4 colons ... */
 
124
#define NUM_COLONS 4
 
125
                if (len > NUM_COLONS) /* ... if possible */
 
126
                        {
 
127
                        int i;
 
128
                        char *s = buf;
 
129
                        
 
130
                        for (i = 0; i < NUM_COLONS; i++)
 
131
                                {
 
132
                                char *colon = strchr(s, ':');
 
133
                                if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
 
134
                                        {
 
135
                                        /* set colon no. i at last possible position
 
136
                                         * (buf[len-1] is the terminating 0)*/
 
137
                                        colon = &buf[len-1] - NUM_COLONS + i;
 
138
                                        *colon = ':';
 
139
                                        }
 
140
                                s = colon + 1;
 
141
                                }
 
142
                        }
 
143
                }
 
144
        }
 
145
 
 
146
/* BAD for multi-threading: uses a local buffer if ret == NULL */
 
147
/* ERR_error_string_n should be used instead for ret != NULL
 
148
 * as ERR_error_string cannot know how large the buffer is */
 
149
char *ERR_error_string(unsigned long e, char *ret)
 
150
        {
 
151
        static char buf[256];
 
152
 
 
153
        if (ret == NULL) ret=buf;
 
154
        ERR_error_string_n(e, ret, 256);
 
155
 
 
156
        return ret;
 
157
        }