~bratsche/vlc/vlc-notify-add-actions-with-server-support

« back to all changes in this revision

Viewing changes to extras/faad2/aacDECdrop/misc.c

  • Committer: Bazaar Package Importer
  • Date: 2008-11-28 09:29:51 UTC
  • Revision ID: jamesw@ubuntu.com-20081128092951-0y5ojboptscru17f
Tags: upstream-ubuntu-0.8.6.release.e+x264svn20071224+faad2.6.1
ImportĀ upstreamĀ versionĀ 0.8.6.release.e+x264svn20071224+faad2.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * function: Miscellaneous functions for aacDECdrop
3
 
 *
4
 
 * This program is distributed under the GNU General Public License, version 2.
5
 
 * A copy of this license is included with this source.
6
 
 *
7
 
 * Copyright (C) 2002 John Edwards
8
 
 */
9
 
 
10
 
#include <stdlib.h>
11
 
#include <stdio.h>
12
 
#include <string.h>
13
 
#include <windows.h>
14
 
#include "misc.h"
15
 
 
16
 
static char *_filename;
17
 
void (*error_handler)(const char *fmt, ...) = error_dialog;
18
 
 
19
 
/*
20
 
 * Set the current input file name.
21
 
 */
22
 
 
23
 
void set_filename(char *filename)
24
 
{
25
 
        _filename = filename;
26
 
}
27
 
 
28
 
/*
29
 
 * Display an error dialog, possibly adding system error information.
30
 
 */
31
 
 
32
 
void error_dialog(const char *fmt, ...)
33
 
{
34
 
        va_list ap;
35
 
        char msgbuf[1024];
36
 
        char *bufp = msgbuf;
37
 
 
38
 
        /* A really rough sanity check to protect against blatant buffer overrun */
39
 
        if (strlen(fmt) > 750)
40
 
        {
41
 
                sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
42
 
        } 
43
 
        else 
44
 
        {
45
 
                if (_filename != NULL && strlen(_filename) < 255)
46
 
                {
47
 
                        sprintf(msgbuf, "%s: ", _filename);
48
 
                        bufp += strlen(msgbuf);
49
 
                }
50
 
 
51
 
                va_start(ap, fmt);
52
 
                
53
 
                vsprintf(bufp, fmt, ap);
54
 
 
55
 
                va_end(ap);
56
 
 
57
 
                if (errno != 0)
58
 
                {
59
 
                        bufp = msgbuf + strlen(msgbuf);
60
 
                        sprintf(bufp, " error is %s (%d)", strerror(errno), errno);
61
 
                        errno = 0;
62
 
                }
63
 
        }
64
 
 
65
 
        MessageBox(NULL, msgbuf, "Error", 0);
66
 
}
67
 
 
68
 
void log_error(const char *fmt, ...)
69
 
{
70
 
        va_list ap;
71
 
        FILE *fp;
72
 
        char msgbuf[1024];
73
 
        char *bufp = msgbuf;
74
 
 
75
 
        /* A really rough sanity check to protect against blatant buffer overrun */
76
 
        if (strlen(fmt) > 750)
77
 
        {
78
 
                sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
79
 
        }
80
 
        else
81
 
        {
82
 
                if (_filename != NULL && strlen(_filename) < 255)
83
 
                {
84
 
                        sprintf(msgbuf, "%s : ", _filename);
85
 
                        bufp += strlen(msgbuf);
86
 
                }
87
 
 
88
 
                va_start(ap, fmt);
89
 
 
90
 
                vsprintf(bufp, fmt, ap);
91
 
 
92
 
                va_end(ap);
93
 
 
94
 
                if (errno != 0)
95
 
                {
96
 
                        bufp = msgbuf + strlen(msgbuf);
97
 
                        sprintf(bufp, " error is: %s (%d)", strerror(errno), errno);
98
 
                        errno = 0;
99
 
                }
100
 
        }
101
 
 
102
 
        va_start(ap, fmt);
103
 
 
104
 
        if ((fp = fopen("oggdrop.log", "a")) == (FILE *)NULL)
105
 
                return;
106
 
 
107
 
        fprintf(fp, "%s\n", msgbuf);
108
 
        fflush(fp);
109
 
        fclose(fp);
110
 
 
111
 
        va_end(ap);
112
 
}
113
 
 
114
 
void set_use_dialogs(int use_dialogs)
115
 
{
116
 
        if (!use_dialogs)
117
 
                error_handler = error_dialog;
118
 
        else
119
 
                error_handler = log_error;
120
 
}
121
 
 
122
 
 
123
 
/******************************** end of misc.c ********************************/
124
 
 
 
1
/*
 
2
 * function: Miscellaneous functions for aacDECdrop
 
3
 *
 
4
 * This program is distributed under the GNU General Public License, version 2.
 
5
 * A copy of this license is included with this source.
 
6
 *
 
7
 * Copyright (C) 2002 John Edwards
 
8
 */
 
9
 
 
10
#include <stdlib.h>
 
11
#include <stdio.h>
 
12
#include <string.h>
 
13
#include <windows.h>
 
14
#include "misc.h"
 
15
 
 
16
static char *_filename;
 
17
void (*error_handler)(const char *fmt, ...) = error_dialog;
 
18
 
 
19
/*
 
20
 * Set the current input file name.
 
21
 */
 
22
 
 
23
void set_filename(char *filename)
 
24
{
 
25
        _filename = filename;
 
26
}
 
27
 
 
28
/*
 
29
 * Display an error dialog, possibly adding system error information.
 
30
 */
 
31
 
 
32
void error_dialog(const char *fmt, ...)
 
33
{
 
34
        va_list ap;
 
35
        char msgbuf[1024];
 
36
        char *bufp = msgbuf;
 
37
 
 
38
        /* A really rough sanity check to protect against blatant buffer overrun */
 
39
        if (strlen(fmt) > 750)
 
40
        {
 
41
                sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
 
42
        } 
 
43
        else 
 
44
        {
 
45
                if (_filename != NULL && strlen(_filename) < 255)
 
46
                {
 
47
                        sprintf(msgbuf, "%s: ", _filename);
 
48
                        bufp += strlen(msgbuf);
 
49
                }
 
50
 
 
51
                va_start(ap, fmt);
 
52
                
 
53
                vsprintf(bufp, fmt, ap);
 
54
 
 
55
                va_end(ap);
 
56
 
 
57
                if (errno != 0)
 
58
                {
 
59
                        bufp = msgbuf + strlen(msgbuf);
 
60
                        sprintf(bufp, " error is %s (%d)", strerror(errno), errno);
 
61
                        errno = 0;
 
62
                }
 
63
        }
 
64
 
 
65
        MessageBox(NULL, msgbuf, "Error", 0);
 
66
}
 
67
 
 
68
void log_error(const char *fmt, ...)
 
69
{
 
70
        va_list ap;
 
71
        FILE *fp;
 
72
        char msgbuf[1024];
 
73
        char *bufp = msgbuf;
 
74
 
 
75
        /* A really rough sanity check to protect against blatant buffer overrun */
 
76
        if (strlen(fmt) > 750)
 
77
        {
 
78
                sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
 
79
        }
 
80
        else
 
81
        {
 
82
                if (_filename != NULL && strlen(_filename) < 255)
 
83
                {
 
84
                        sprintf(msgbuf, "%s : ", _filename);
 
85
                        bufp += strlen(msgbuf);
 
86
                }
 
87
 
 
88
                va_start(ap, fmt);
 
89
 
 
90
                vsprintf(bufp, fmt, ap);
 
91
 
 
92
                va_end(ap);
 
93
 
 
94
                if (errno != 0)
 
95
                {
 
96
                        bufp = msgbuf + strlen(msgbuf);
 
97
                        sprintf(bufp, " error is: %s (%d)", strerror(errno), errno);
 
98
                        errno = 0;
 
99
                }
 
100
        }
 
101
 
 
102
        va_start(ap, fmt);
 
103
 
 
104
        if ((fp = fopen("oggdrop.log", "a")) == (FILE *)NULL)
 
105
                return;
 
106
 
 
107
        fprintf(fp, "%s\n", msgbuf);
 
108
        fflush(fp);
 
109
        fclose(fp);
 
110
 
 
111
        va_end(ap);
 
112
}
 
113
 
 
114
void set_use_dialogs(int use_dialogs)
 
115
{
 
116
        if (!use_dialogs)
 
117
                error_handler = error_dialog;
 
118
        else
 
119
                error_handler = log_error;
 
120
}
 
121
 
 
122
 
 
123
/******************************** end of misc.c ********************************/
 
124