diff --git a/ee/libcglue/Makefile b/ee/libcglue/Makefile index f078c86fdfb..4814e2e84a5 100644 --- a/ee/libcglue/Makefile +++ b/ee/libcglue/Makefile @@ -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 @@ -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 \ diff --git a/ee/libcglue/include/sys/socket.h b/ee/libcglue/include/sys/socket.h index 2c11177ecc5..6a60adaf1d0 100644 --- a/ee/libcglue/include/sys/socket.h +++ b/ee/libcglue/include/sys/socket.h @@ -82,6 +82,13 @@ #include #endif +/* + * Maximum queue length specifiable by listen(2). + */ +#ifndef SOMAXCONN +#define SOMAXCONN 128 +#endif + #if 0 #include diff --git a/ee/libcglue/src/fdman.c b/ee/libcglue/src/fdman.c index b9077e8cfe0..7bbf7c1f470 100644 --- a/ee/libcglue/src/fdman.c +++ b/ee/libcglue/src/fdman.c @@ -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) diff --git a/ee/libcglue/src/fdman.h b/ee/libcglue/src/fdman.h index 76f5c85960d..a58a8b44153 100644 --- a/ee/libcglue/src/fdman.h +++ b/ee/libcglue/src/fdman.h @@ -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 diff --git a/ee/libcglue/src/glue.c b/ee/libcglue/src/glue.c index f96b4b98dcd..1e3a073029e 100644 --- a/ee/libcglue/src/glue.c +++ b/ee/libcglue/src/glue.c @@ -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 */ \ No newline at end of file