add annotations

remove warnings when compiling as c++
This commit is contained in:
leitner
2025-01-21 17:09:21 +00:00
parent 402e5b0c39
commit e019297cce
2 changed files with 10 additions and 3 deletions

7
mmap.h
View File

@@ -4,27 +4,34 @@
#include <stddef.h>
#include <libowfat/compiler.h>
#ifdef __cplusplus
extern "C" {
#endif
/* open file for reading, mmap whole file, close file, write length of
* map in filesize and return pointer to map. */
__strin(1) att_write(2)
const char* mmap_read(const char *filename,size_t* filesize);
/* like mmap_read but use openat instead of open */
__strin(1) att_write(2)
const char* mmap_readat(const char *filename,size_t* filesize,int dirfd);
/* open file for reading, mmap whole file privately (copy on write),
* close file, write length of map in filesize and return pointer to
* map. */
__strin(1) att_write(2)
char* mmap_private(const char *filename,size_t* filesize);
/* open file for writing, mmap whole file shared, close file, write
* length of map in filesize and return pointer to map. */
__strin(1) att_write(2)
char* mmap_shared(const char *filename,size_t* filesize);
/* unmap a mapped region */
__strin(1)
int mmap_unmap(const char* mapped,size_t maplen);
#ifdef __cplusplus

View File

@@ -27,15 +27,15 @@ extern const char* mmap_read(const char* filename,size_t * filesize) {
int fd=open_read(filename);
char *map;
if (fd>=0) {
register off_t o=lseek(fd,0,SEEK_END);
off_t o=lseek(fd,0,SEEK_END);
if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; }
*filesize=(size_t)o;
if (o>0) {
map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0);
map=(char*)mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0);
if (map==(char*)-1)
map=0;
} else
map="";
map=(char*)"";
close(fd);
return map;
}