Skip to content

Commit ca93e7d

Browse files
committed
wav_{reader,writer}: IWYU
1 parent c211683 commit ca93e7d

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

src/audio/wav_reader.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
*/
3737

38-
#ifdef HAVE_CONFIG_H
39-
#include "config.h"
40-
#include "config_unix.h"
41-
#include "config_win32.h"
42-
#endif // HAVE_CONFIG_H
43-
38+
#include <assert.h>
39+
#include <errno.h>
4440
#include <inttypes.h>
4541
#include <limits.h>
4642
#include <stdbool.h>
4743
#include <stdint.h>
44+
#include <stdio.h>
45+
#include <string.h>
4846

4947
#include "audio/utils.h"
5048
#include "audio/wav_reader.h"
49+
#define WANT_FSEEKO64
50+
#include "compat/misc.h"
5151
#include "debug.h"
5252
#include "utils/macros.h"
5353
#include "utils/misc.h"
@@ -144,8 +144,8 @@ static _Bool is_member(const char *needle, const char **haystack) {
144144
return 0;
145145
}
146146

147-
static int fskip(FILE *f, long off) {
148-
if (_fseeki64(f, off, SEEK_CUR) == 0) {
147+
static int fskip(FILE *f, long long off) {
148+
if (fseeko(f, off, SEEK_CUR) == 0) {
149149
return 1;
150150
}
151151
while (off-- > 0) {
@@ -162,21 +162,21 @@ static _Bool process_data_chunk(FILE *wav_file, uint32_t chunk_size, struct wav_
162162
if (!found_ds64_chunk) { // RF64 has this chunk size always -1, value from ds64 is used instead
163163
metadata->data_size = chunk_size;
164164
}
165-
metadata->data_offset = _ftelli64(wav_file);
165+
metadata->data_offset = ftello(wav_file);
166166
if (metadata->data_size != UINT32_MAX || metadata->data_offset == -1) {
167167
return 1;
168168
}
169169

170170
// for UINT32_MAX deduce the length from file length (as FFmpeg does)
171-
if (_fseeki64(wav_file, 0, SEEK_END) != 0) {
171+
if (fseeko(wav_file, 0, SEEK_END) != 0) {
172172
return 1;
173173
}
174-
int64_t data_end = _ftelli64(wav_file);
174+
int64_t data_end = ftello(wav_file);
175175
if (data_end == -1) {
176176
ug_perror(MOD_NAME "cannot get length of file");
177177
return 0;
178178
}
179-
if (_fseeki64(wav_file, metadata->data_offset, SEEK_SET) != 0) {
179+
if (fseeko(wav_file, metadata->data_offset, SEEK_SET) != 0) {
180180
ug_perror(MOD_NAME "cannot seek back to data chunk");
181181
return 0;
182182
}

src/audio/wav_writer.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,17 @@
5858
* also follows the above rules.
5959
*/
6060

61-
#ifdef HAVE_CONFIG_H
62-
#include "config.h"
63-
#include "config_unix.h"
64-
#include "config_win32.h"
65-
#endif /* HAVE_CONFIG_H */
66-
61+
#include <errno.h> // for errno
62+
#include <limits.h> // for CHAR_BIT
6763
#include <stdint.h>
6864
#include <stdio.h>
6965
#include <stdlib.h>
7066

67+
#include "audio/types.h" // for audio_desc
7168
#include "audio/utils.h"
7269
#include "audio/wav_writer.h"
70+
#define WANT_FSEEKO64
71+
#include "compat/misc.h" // for fseeko, ftello
7372

7473
/* Chunk size: 4 + 24 + (8 + M * Nc * Ns + (0 or 1)) */
7574
#define CK_MASTER_SIZE_OFFSET 4
@@ -177,7 +176,7 @@ bool wav_writer_close(struct wav_writer_file *wav)
177176
}
178177
}
179178

180-
int64_t ret = _fseeki64(wav->outfile, CK_MASTER_SIZE_OFFSET, SEEK_SET);
179+
int64_t ret = fseeko(wav->outfile, CK_MASTER_SIZE_OFFSET, SEEK_SET);
181180
if (ret != 0) {
182181
goto error;
183182
}
@@ -193,7 +192,7 @@ bool wav_writer_close(struct wav_writer_file *wav)
193192
goto error;
194193
}
195194

196-
ret = _fseeki64(wav->outfile, CK_DATA_SIZE_OFFSET, SEEK_SET);
195+
ret = fseeko(wav->outfile, CK_DATA_SIZE_OFFSET, SEEK_SET);
197196
if (ret != 0) {
198197
goto error;
199198
}

src/audio/wav_writer.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,15 @@
3838
#ifndef WAV_WRITER_H_722362F0_155A_11EC_88ED_B7401531ECA5
3939
#define WAV_WRITER_H_722362F0_155A_11EC_88ED_B7401531ECA5
4040

41-
#ifdef __cplusplus
42-
#include <cstdio>
43-
#else
41+
#ifndef __cplusplus
4442
#include <stdbool.h>
45-
#include <stdio.h>
4643
#endif
4744

48-
#include "audio/types.h"
49-
5045
#ifdef __cplusplus
5146
extern "C" {
5247
#endif
5348

49+
struct audio_desc;
5450
struct wav_writer_file;
5551

5652
/**

src/compat/misc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,18 @@
5050
#endif
5151
#endif // defined WANT_MKDIR
5252

53+
#ifdef WANT_FSEEKO64
54+
#include <stdio.h>
55+
#ifdef _WIN32
56+
#define ftello _ftelli64
57+
#define fseeko _fseeki64
58+
#else
59+
#ifndef __cplusplus
60+
#include <assert.h> // static_assert macro (until c32)
61+
#endif
62+
static_assert(sizeof(off_t) > 4, "32b off_t");
63+
#endif // !defined _WIN32
64+
#endif // defined WANT_FSEEKO
65+
5366
#endif // defined COMPAT_MISC_H_20C709DB_F4A8_4744_A0A9_96036B277011
5467

src/config_unix.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ typedef int fd_t;
170170
#define INVALID_SOCKET (-1)
171171
#define CLOSESOCKET close
172172

173-
#define _ftelli64 ftell
174-
#define _fseeki64 fseek
175-
176173
#ifdef __cplusplus
177174
#define CONF_NIX_EXT_C extern "C"
178175
#else

0 commit comments

Comments
 (0)