VLC  3.0.15
vlc_memstream.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_memstream.h:
3  *****************************************************************************
4  * Copyright (C) 2016 RĂ©mi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20 
21 #ifndef VLC_MEMSTREAM_H
22 # define VLC_MEMSTREAM_H 1
23 
24 # include <stdarg.h>
25 # include <stdio.h>
26 
28 {
29  union
30  {
31  FILE *stream;
32  int error;
33  };
34  char *ptr;
35  size_t length;
36 };
37 
38 VLC_API
39 int vlc_memstream_open(struct vlc_memstream *ms);
40 
41 VLC_API
43 
44 VLC_API
46 
47 VLC_API
48 size_t vlc_memstream_write(struct vlc_memstream *ms,
49  const void *ptr, size_t len);
50 
52 int vlc_memstream_putc(struct vlc_memstream *ms, int c);
53 
54 VLC_API
55 int vlc_memstream_puts(struct vlc_memstream *ms, const char *str);
56 
57 VLC_API
58 int vlc_memstream_vprintf(struct vlc_memstream *ms, const char *fmt,
59  va_list args);
60 
61 VLC_API
62 int vlc_memstream_printf(struct vlc_memstream *s, const char *fmt,
63  ...) VLC_FORMAT(2,3);
64 
65 # ifdef __GNUC__
66 static inline int vlc_memstream_puts_len(struct vlc_memstream *ms,
67  const char *str, size_t len)
68 {
69  return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
70 }
71 # define vlc_memstream_puts(ms,s) \
72  (__builtin_constant_p(__builtin_strlen(s)) ? \
73  vlc_memstream_puts_len(ms,s,__builtin_strlen(s)) : \
74  vlc_memstream_puts(ms,s))
75 # endif
76 #endif /* VLC_MEMSTREAM_H */
VLC_FORMAT
#define VLC_FORMAT(x, y)
Definition: vlc_common.h:100
VLC_API
#define VLC_API
Definition: fourcc_gen.c:30
vlc_memstream
Definition: vlc_memstream.h:27
vlc_memstream::ptr
char * ptr
Definition: vlc_memstream.h:51
vlc_memstream::error
int error
Definition: vlc_memstream.h:66
vlc_common.h
vlc_memstream::length
size_t length
Definition: vlc_memstream.h:52
vlc_memstream_write
size_t vlc_memstream_write(struct vlc_memstream *ms, const void *ptr, size_t len)
Definition: memstream.c:126
vlc_memstream_flush
int vlc_memstream_flush(struct vlc_memstream *ms)
Definition: memstream.c:114
vlc_memstream_putc
int vlc_memstream_putc(struct vlc_memstream *ms, int c)
Definition: memstream.c:144
vlc_memstream::stream
FILE * stream
Definition: vlc_memstream.h:65
vlc_memstream_puts
int vlc_memstream_puts(struct vlc_memstream *ms, const char *str)
Definition: memstream.c:149
vlc_memstream_printf
int vlc_memstream_printf(struct vlc_memstream *s, const char *fmt,...)
Definition: memstream.c:184
vlc_memstream_close
int vlc_memstream_close(struct vlc_memstream *ms)
Definition: memstream.c:119
VLC_USED
#define VLC_USED
Definition: fourcc_gen.c:31
vlc_memstream_vprintf
int vlc_memstream_vprintf(struct vlc_memstream *ms, const char *fmt, va_list args)
Definition: memstream.c:155
vlc_memstream_open
int vlc_memstream_open(struct vlc_memstream *ms)
Definition: memstream.c:104