/*
 * Copyright ©2026 Soham Pardeshi. All rights reserved.
 * Permission is hereby granted to students registered for University of
 * Washington CSE 333 for use solely during Summer Quarter 2026 for
 * purposes of the course. No other use, copying, distribution, or
 * modification is permitted without prior written consent. Copyrights
 * for third-party components of this work must be honored. Instructors
 * interested in reusing these course materials should contact the author.
 */

#ifndef FILEUTIL_H_
#define FILEUTIL_H_

#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

// Returns the size of the specified file in bytes, or -1 on any error.
ssize_t FileSize(const char* filename);

// Reads the contents of the specified file into 'buf', reading at most
// 'buflen' bytes total and at most 'chunk_size' bytes per read() call.
// Returns the number of bytes placed in 'buf', or -1 on any error. Note
// that the contents are raw bytes, NOT a C string (no '\0' terminator is
// added).
//
// 'chunk_size' sets the read granularity: a small chunk_size (e.g. 1)
// forces many small read() system calls, while a large chunk_size reads
// in fewer, bigger calls. It must be greater than 0.
ssize_t ReadFile(const char* filename, char* buf, size_t buflen,
                 size_t chunk_size);

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // FILEUTIL_H_