mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 07:58:22 +00:00
Add git_fsize to the os file API
This permits us to get the size of an opened file. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
3e9e69098a
commit
2dbdb824f0
@ -26,11 +26,16 @@
|
|||||||
#ifndef INCLUDE_git_os_abstraction_h__
|
#ifndef INCLUDE_git_os_abstraction_h__
|
||||||
#define INCLUDE_git_os_abstraction_h__
|
#define INCLUDE_git_os_abstraction_h__
|
||||||
|
|
||||||
|
/** Force 64 bit off_t size on POSIX. */
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,6 +100,15 @@ GIT_EXTERN(int) git_fread(git_file fd, void *buf, size_t cnt);
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_fwrite(git_file fd, void *buf, size_t cnt);
|
GIT_EXTERN(int) git_fwrite(git_file fd, void *buf, size_t cnt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current size of an open file.
|
||||||
|
* @param fd open descriptor.
|
||||||
|
* @return
|
||||||
|
* - On success, >= 0, indicating the file size in bytes.
|
||||||
|
* - On error, <0.
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(off_t) git_fsize(git_file fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close an open file descriptor.
|
* Close an open file descriptor.
|
||||||
* @param fd descriptor to close.
|
* @param fd descriptor to close.
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include "git/common.h"
|
#include "git/common.h"
|
||||||
|
|
||||||
int git_fopen(git_file *out, const char *path, int flags)
|
int git_fopen(git_file *out, const char *path, int flags)
|
||||||
@ -74,3 +73,11 @@ int git_fwrite(git_file fd, void *buf, size_t cnt)
|
|||||||
}
|
}
|
||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
off_t git_fsize(git_file fd)
|
||||||
|
{
|
||||||
|
struct stat sb;
|
||||||
|
if (fstat(fd, &sb))
|
||||||
|
return -1;
|
||||||
|
return sb.st_size;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user