Skip to content

Commit

Permalink
Merge pull request #626 from fjtrujy/missingFunctions
Browse files Browse the repository at this point in the history
Missing functions
  • Loading branch information
fjtrujy authored May 31, 2024
2 parents a793291 + ae48c0a commit 8d2a6a4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ee/libcglue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ CORE_OBJS = rtc.o

TIMEZONE_OBJS = _libcglue_timezone_update.o ps2sdk_setTimezone.o ps2sdk_setDaylightSaving.o

FDMAN_OBJS = __fdman_sema.o __descriptor_data_pool.o __descriptormap.o __fdman_init.o __fdman_deinit.o __fdman_get_new_descriptor.o \
__fdman_get_dup_descriptor.o __fdman_release_descriptor.o
FDMAN_OBJS = \
__fdman_sema.o \
__descriptor_data_pool.o \
__descriptormap.o \
__fdman_init.o \
__fdman_deinit.o \
__fdman_get_new_descriptor.o \
__fdman_get_dup_descriptor.o \
__fdman_get_dup2_descriptor.o \
__fdman_release_descriptor.o

INIT_OBJS = __libpthreadglue_init.o __libpthreadglue_deinit.o _libcglue_init.o _libcglue_deinit.o _libcglue_args_parse.o

Expand Down Expand Up @@ -117,7 +125,9 @@ GLUE_OBJS = \
fchownat.o \
linkat.o \
readlinkat.o \
unlinkat.o
unlinkat.o \
dup.o \
dup2.o \

LOCK_OBJS = \
__lock___sfp_recursive_mutex.o \
Expand Down
7 changes: 7 additions & 0 deletions ee/libcglue/include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
#include <tcpip.h>
#endif

/*
* Maximum queue length specifiable by listen(2).
*/
#ifndef SOMAXCONN
#define SOMAXCONN 128
#endif

#if 0
#include <sys/featuretest.h>

Expand Down
16 changes: 16 additions & 0 deletions ee/libcglue/src/fdman.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ int __fdman_get_dup_descriptor(int fd)
}
#endif

#ifdef F___fdman_get_dup_descriptor
int __fdman_get_dup2_descriptor(int fd, int newfd)
{
if (!__IS_FD_VALID(fd)) {
errno = EBADF;
return -1;
}

WaitSema(__fdman_sema); /* lock here to make thread safe */
__descriptormap[newfd] = &__descriptor_data_pool[fd];
__descriptormap[newfd]->ref_count++;
SignalSema(__fdman_sema); /* release lock */

return newfd;
}
#endif

#ifdef F___fdman_release_descriptor
void __fdman_release_descriptor(int fd)
Expand Down
1 change: 1 addition & 0 deletions ee/libcglue/src/fdman.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void __fdman_init();
void __fdman_deinit();
int __fdman_get_new_descriptor();
int __fdman_get_dup_descriptor(int fd);
int __fdman_get_dup2_descriptor(int fd, int newfd);
void __fdman_release_descriptor(int fd);

#endif
34 changes: 34 additions & 0 deletions ee/libcglue/src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,3 +1191,37 @@ int unlinkat(int dirfd, const char *pathname, int flags)
}
}
#endif /* F_unlinkat */

#ifdef F_dup
int dup(int oldfd)
{
if (!__IS_FD_VALID(oldfd)) {
errno = EBADF;
return -1;
}

return __fdman_get_dup_descriptor(oldfd);
}
#endif /* F_dup */

#ifdef F_dup2
int dup2(int oldfd, int newfd)
{
if (!__IS_FD_VALID(oldfd)) {
errno = EBADF;
return -1;
}

if (oldfd == newfd) {
return oldfd;
}
if (newfd < 0) {
errno = EBADF;
return -1;
}
if (__descriptormap[newfd]) {
close(newfd);
}
return __fdman_get_dup2_descriptor(oldfd, newfd);
}
#endif /* F_dup2 */

0 comments on commit 8d2a6a4

Please sign in to comment.