-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1063 from Qwinci/lfs64-additions
Lfs64 additions, hsearch family of functions and icmp6 define
- Loading branch information
Showing
22 changed files
with
283 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <bits/glibc/glibc_search.h> | ||
#include <mlibc/search.hpp> | ||
|
||
int hcreate_r(size_t num_entries, hsearch_data *htab) { | ||
return mlibc::hcreate_r(num_entries, htab); | ||
} | ||
|
||
void hdestroy_r(hsearch_data *htab) { | ||
mlibc::hdestroy_r(htab); | ||
} | ||
|
||
int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, hsearch_data *htab) { | ||
return mlibc::hsearch_r(item, action, ret, htab); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef _GLIBC_SEARCH_H | ||
#define _GLIBC_SEARCH_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <bits/search.h> | ||
|
||
#ifndef __MLIBC_ABI_ONLY | ||
|
||
int hcreate_r(size_t num_entries, struct hsearch_data *htab); | ||
void hdestroy_r(struct hsearch_data *htab); | ||
int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, struct hsearch_data *htab); | ||
|
||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _GLIBC_SEARCH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include <mlibc/search.hpp> | ||
#include <frg/string.hpp> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <errno.h> | ||
|
||
struct _ENTRY { | ||
ENTRY entry; | ||
bool used; | ||
}; | ||
|
||
namespace mlibc { | ||
|
||
int hcreate_r(size_t num_entries, struct hsearch_data *htab) { | ||
if(!htab) { | ||
errno = EINVAL; | ||
return 0; | ||
} | ||
|
||
htab->table = static_cast<_ENTRY*>(calloc(num_entries, sizeof(_ENTRY))); | ||
if(!htab->table) { | ||
errno = ENOMEM; | ||
return 0; | ||
} | ||
htab->filled = 0; | ||
htab->size = num_entries; | ||
return 1; | ||
} | ||
|
||
void hdestroy_r(struct hsearch_data *htab) { | ||
if(!htab) { | ||
errno = EINVAL; | ||
return; | ||
} | ||
free(htab->table); | ||
htab->table = nullptr; | ||
htab->size = 0; | ||
htab->filled = 0; | ||
} | ||
|
||
|
||
int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, struct hsearch_data *htab) { | ||
auto key = frg::string_view{item.key}; | ||
auto hash = frg::hash<frg::string_view>{}(key); | ||
|
||
size_t bucket_index = hash % htab->size; | ||
size_t start = bucket_index; | ||
while(true) { | ||
auto &bucket = htab->table[bucket_index]; | ||
|
||
if(bucket.used) { | ||
if(bucket.entry.key == key) { | ||
*ret = &bucket.entry; | ||
return 1; | ||
} | ||
} else if(action == FIND) { | ||
errno = ESRCH; | ||
*ret = nullptr; | ||
return 0; | ||
} | ||
|
||
bucket_index = (bucket_index + 1) % htab->size; | ||
|
||
if(bucket_index == start) { | ||
if(action == FIND) { | ||
errno = ESRCH; | ||
*ret = nullptr; | ||
return 0; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// insert a new entry. | ||
if(htab->size == htab->filled) { | ||
errno = ENOMEM; | ||
return 0; | ||
} | ||
++htab->filled; | ||
|
||
bucket_index = start; | ||
while(true) { | ||
auto &bucket = htab->table[bucket_index]; | ||
if(!bucket.used) { | ||
bucket.used = true; | ||
bucket.entry = item; | ||
*ret = &bucket.entry; | ||
break; | ||
} | ||
|
||
bucket_index = (bucket_index + 1) % htab->size; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
} // namespace mlibc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef _MLIBC_INTERNAL_SEARCH_H | ||
#define _MLIBC_INTERNAL_SEARCH_H | ||
|
||
#include <bits/size_t.h> | ||
|
||
typedef enum { | ||
FIND, | ||
ENTER | ||
} ACTION; | ||
|
||
typedef struct entry { | ||
char *key; | ||
void *data; | ||
} ENTRY; | ||
|
||
struct _ENTRY; | ||
|
||
struct hsearch_data { | ||
struct _ENTRY *table; | ||
unsigned int size; | ||
unsigned int filled; | ||
}; | ||
|
||
#endif /* _MLIBC_INTERNAL_SEARCH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef MLIBC_SEARCH | ||
#define MLIBC_SEARCH | ||
|
||
#include <bits/search.h> | ||
|
||
namespace mlibc { | ||
|
||
int hcreate_r(size_t num_entries, struct hsearch_data *htab); | ||
void hdestroy_r(struct hsearch_data *htab); | ||
int hsearch_r(ENTRY item, ACTION action, ENTRY **ret, struct hsearch_data *htab); | ||
|
||
} // namespace mlibc | ||
|
||
#endif // MLIBC_SEARCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ int flock(int fd, int opt) { | |
return 0; | ||
} | ||
|
||
[[gnu::alias("flock")]] int flock64(int fd, int opt); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.