Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libdvbpsi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
libdvbpsi
Commits
9b3cc048
Commit
9b3cc048
authored
Feb 09, 2011
by
Jean-Paul Saman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src/dvbpsi.c: simplify logging code
Less duplicate code.
parent
7e1ae788
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
80 deletions
+67
-80
src/dvbpsi.c
src/dvbpsi.c
+67
-80
No files found.
src/dvbpsi.c
View file @
9b3cc048
...
@@ -431,8 +431,9 @@ void dvbpsi_PushPacket(dvbpsi_t *handle, uint8_t* p_data)
...
@@ -431,8 +431,9 @@ void dvbpsi_PushPacket(dvbpsi_t *handle, uint8_t* p_data)
* 1 is warning and errors
* 1 is warning and errors
* 2 is debug, warning and errors
* 2 is debug, warning and errors
*****************************************************************************/
*****************************************************************************/
#if !defined(_GNU_SOURCE)
#define DVBPSI_MSG_FORMAT "libdvbpsi (%s): "
# define DVBPSI_MSG_SIZE 1024
#endif
#ifdef HAVE_VARIADIC_MACROS
#ifdef HAVE_VARIADIC_MACROS
void
message
(
dvbpsi_t
*
dvbpsi
,
const
int
level
,
const
char
*
fmt
,
...)
void
message
(
dvbpsi_t
*
dvbpsi
,
const
int
level
,
const
char
*
fmt
,
...)
...
@@ -442,111 +443,97 @@ void message(dvbpsi_t *dvbpsi, const int level, const char *fmt, ...)
...
@@ -442,111 +443,97 @@ void message(dvbpsi_t *dvbpsi, const int level, const char *fmt, ...)
{
{
va_list
ap
;
va_list
ap
;
va_start
(
ap
,
fmt
);
va_start
(
ap
,
fmt
);
#if defined(_GNU_SOURCE)
char
*
msg
=
NULL
;
char
*
msg
=
NULL
;
#if defined(_GNU_SOURCE)
int
err
=
vasprintf
(
&
msg
,
fmt
,
ap
);
int
err
=
vasprintf
(
&
msg
,
fmt
,
ap
);
#else
#else
char
msg
[
1024
];
msg
=
malloc
(
DVBPSI_MSG_SIZE
);
int
err
=
vsnprintf
(
&
msg
,
1024
,
fmt
,
ap
);
if
(
msg
==
NULL
)
return
;
if
(
snprintf
(
&
msg
,
DVBPSI_MSG_SIZE
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
{
free
(
msg
);
return
;
}
int
err
=
vsnprintf
(
&
msg
,
DVBPSI_MSG_SIZE
,
fmt
,
ap
);
#endif
#endif
va_end
(
ap
);
va_end
(
ap
);
if
(
err
>
DVBPSI_MSG_NONE
)
{
if
(
err
>
DVBPSI_MSG_NONE
)
{
if
(
dvbpsi
->
pf_message
)
if
(
dvbpsi
->
pf_message
)
dvbpsi
->
pf_message
(
dvbpsi
,
msg
);
dvbpsi
->
pf_message
(
dvbpsi
,
msg
);
#if defined(_GNU_SOURCE)
free
(
msg
);
#endif
}
}
free
(
msg
);
}
}
}
}
#else
#else
# define DVBPSI_MSG_FORMAT "libdvbpsi (%s): %s"
/* Common code for printing messages */
# if defined(_GNU_SOURCE)
# define DVBPSI_MSG_COMMON \
do { \
va_list ap; \
va_start(ap, fmt); \
char *tmp = NULL; \
int err = vasprintf(&tmp, fmt, ap); \
if (err < 0) \
return; \
char *msg = NULL; \
if (asprintf(&msg, DVBPSI_MSG_FORMAT, src, tmp) < 0) { \
free(tmp); \
return; \
} \
free(tmp); \
va_end(ap); \
if (err > 0) { \
if (dvbpsi->pf_message) \
dvbpsi->pf_message(dvbpsi, msg); \
} \
free(msg); \
} while(0);
# else
# define DVBPSI_MSG_COMMON \
do { \
va_list ap; \
va_start(ap, fmt); \
char *msg = malloc(DVBPSI_MSG_SIZE); \
if (msg == NULL) \
return; \
if (snprintf(&msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, src) < 0) \
return; \
int err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap); \
va_end(ap); \
if (err > 0) { \
if (dvbpsi->pf_message) \
dvbpsi->pf_message(dvbpsi, msg); \
} \
free(msg); \
} while(0);
# endif
void
dvbpsi_error
(
dvbpsi_t
*
dvbpsi
,
const
char
*
src
,
const
char
*
fmt
,
...)
void
dvbpsi_error
(
dvbpsi_t
*
dvbpsi
,
const
char
*
src
,
const
char
*
fmt
,
...)
{
{
if
(
DVBPSI_MSG_ERROR
<=
dvbpsi
->
i_msg_level
)
if
((
dvbpsi
->
i_msg_level
>
DVBPSI_MSG_NONE
)
&&
(
DVBPSI_MSG_ERROR
<=
dvbpsi
->
i_msg_level
))
{
{
va_list
ap
;
DVBPSI_MSG_COMMON
va_start
(
ap
,
fmt
);
#if defined(_GNU_SOURCE)
char
*
msg
=
NULL
;
if
(
asprintf
(
&
msg
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
return
;
int
err
=
vasprintf
(
&
msg
,
fmt
,
ap
);
#else
char
*
msg
=
malloc
(
1024
);
if
(
msg
==
NULL
)
return
;
if
(
snprintf
(
&
msg
,
1024
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
return
;
int
err
=
vsnprintf
(
&
msg
,
1024
,
fmt
,
ap
);
#endif
va_end
(
ap
);
if
(
err
>
0
)
{
if
(
dvbpsi
->
pf_message
)
dvbpsi
->
pf_message
(
dvbpsi
,
msg
);
#if defined(_GNU_SOURCE)
free
(
msg
);
#endif
}
}
}
}
}
void
dvbpsi_warning
(
dvbpsi_t
*
dvbpsi
,
const
char
*
src
,
const
char
*
fmt
,
...)
void
dvbpsi_warning
(
dvbpsi_t
*
dvbpsi
,
const
char
*
src
,
const
char
*
fmt
,
...)
{
{
if
(
DVBPSI_MSG_WARN
<=
dvbpsi
->
i_msg_level
)
if
((
dvbpsi
->
i_msg_level
>
DVBPSI_MSG_NONE
)
&&
(
DVBPSI_MSG_WARN
<=
dvbpsi
->
i_msg_level
))
{
{
va_list
ap
;
DVBPSI_MSG_COMMON
va_start
(
ap
,
fmt
);
#if defined(_GNU_SOURCE)
char
*
msg
=
NULL
;
if
(
asprintf
(
&
msg
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
return
;
int
err
=
vasprintf
(
&
msg
,
fmt
,
ap
);
#else
char
*
msg
=
malloc
(
1024
);
if
(
msg
==
NULL
)
return
;
if
(
snprintf
(
&
msg
,
1024
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
return
;
int
err
=
vsnprintf
(
&
msg
,
1024
,
fmt
,
ap
);
#endif
va_end
(
ap
);
if
(
err
>
0
)
{
if
(
dvbpsi
->
pf_message
)
dvbpsi
->
pf_message
(
dvbpsi
,
msg
);
#if defined(_GNU_SOURCE)
free
(
msg
);
#endif
}
}
}
}
}
void
dvbpsi_debug
(
dvbpsi_t
*
dvbpsi
,
const
char
*
src
,
const
char
*
fmt
,
...)
void
dvbpsi_debug
(
dvbpsi_t
*
dvbpsi
,
const
char
*
src
,
const
char
*
fmt
,
...)
{
{
if
(
DVBPSI_MSG_DEBUG
<=
dvbpsi
->
i_msg_level
)
if
((
dvbpsi
->
i_msg_level
>
DVBPSI_MSG_NONE
)
&&
(
DVBPSI_MSG_DEBUG
<=
dvbpsi
->
i_msg_level
))
{
{
va_list
ap
;
DVBPSI_MSG_COMMON
va_start
(
ap
,
fmt
);
#if defined(_GNU_SOURCE)
char
*
msg
=
NULL
;
if
(
asprintf
(
&
msg
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
return
;
int
err
=
vasprintf
(
&
msg
,
fmt
,
ap
);
#else
char
*
msg
=
malloc
(
1024
);
if
(
msg
==
NULL
)
return
;
if
(
snprintf
(
&
msg
,
1024
,
DVBPSI_MSG_FORMAT
,
src
)
<
0
)
return
;
int
err
=
vsnprintf
(
&
msg
,
1024
,
fmt
,
ap
);
#endif
va_end
(
ap
);
if
(
err
>
0
)
{
if
(
dvbpsi
->
pf_message
)
dvbpsi
->
pf_message
(
dvbpsi
,
msg
);
#if defined(_GNU_SOURCE)
free
(
msg
);
#endif
}
}
}
}
}
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment