@@ -142,10 +142,8 @@ int sys_chmod(const char *path, mode_t mode)
142142{
143143#if defined(__NR_fchmodat )
144144 return my_syscall4 (__NR_fchmodat , AT_FDCWD , path , mode , 0 );
145- #elif defined(__NR_chmod )
146- return my_syscall2 (__NR_chmod , path , mode );
147145#else
148- return __nolibc_enosys ( __func__ , path , mode );
146+ return my_syscall2 ( __NR_chmod , path , mode );
149147#endif
150148}
151149
@@ -165,10 +163,8 @@ int sys_chown(const char *path, uid_t owner, gid_t group)
165163{
166164#if defined(__NR_fchownat )
167165 return my_syscall5 (__NR_fchownat , AT_FDCWD , path , owner , group , 0 );
168- #elif defined(__NR_chown )
169- return my_syscall3 (__NR_chown , path , owner , group );
170166#else
171- return __nolibc_enosys ( __func__ , path , owner , group );
167+ return my_syscall3 ( __NR_chown , path , owner , group );
172168#endif
173169}
174170
@@ -238,11 +234,22 @@ static __attribute__((unused))
238234int sys_dup2 (int old , int new )
239235{
240236#if defined(__NR_dup3 )
237+ int ret , nr_fcntl ;
238+
239+ #ifdef __NR_fcntl64
240+ nr_fcntl = __NR_fcntl64 ;
241+ #else
242+ nr_fcntl = __NR_fcntl ;
243+ #endif
244+
245+ if (old == new ) {
246+ ret = my_syscall2 (nr_fcntl , old , F_GETFD );
247+ return ret < 0 ? ret : old ;
248+ }
249+
241250 return my_syscall3 (__NR_dup3 , old , new , 0 );
242- #elif defined(__NR_dup2 )
243- return my_syscall2 (__NR_dup2 , old , new );
244251#else
245- return __nolibc_enosys ( __func__ , old , new );
252+ return my_syscall2 ( __NR_dup2 , old , new );
246253#endif
247254}
248255
@@ -327,10 +334,8 @@ pid_t sys_fork(void)
327334 * will not use the rest with no other flag.
328335 */
329336 return my_syscall5 (__NR_clone , SIGCHLD , 0 , 0 , 0 , 0 );
330- #elif defined(__NR_fork )
331- return my_syscall0 (__NR_fork );
332337#else
333- return __nolibc_enosys ( __func__ );
338+ return my_syscall0 ( __NR_fork );
334339#endif
335340}
336341#endif
@@ -347,7 +352,7 @@ pid_t sys_vfork(void)
347352{
348353#if defined(__NR_vfork )
349354 return my_syscall0 (__NR_vfork );
350- #elif defined( __NR_clone3 )
355+ #else
351356 /*
352357 * clone() could be used but has different argument orders per
353358 * architecture.
@@ -358,8 +363,6 @@ pid_t sys_vfork(void)
358363 };
359364
360365 return my_syscall2 (__NR_clone3 , & args , sizeof (args ));
361- #else
362- return __nolibc_enosys (__func__ );
363366#endif
364367}
365368#endif
@@ -569,10 +572,8 @@ int sys_link(const char *old, const char *new)
569572{
570573#if defined(__NR_linkat )
571574 return my_syscall5 (__NR_linkat , AT_FDCWD , old , AT_FDCWD , new , 0 );
572- #elif defined(__NR_link )
573- return my_syscall2 (__NR_link , old , new );
574575#else
575- return __nolibc_enosys ( __func__ , old , new );
576+ return my_syscall2 ( __NR_link , old , new );
576577#endif
577578}
578579
@@ -593,41 +594,27 @@ off_t sys_lseek(int fd, off_t offset, int whence)
593594#if defined(__NR_lseek )
594595 return my_syscall3 (__NR_lseek , fd , offset , whence );
595596#else
596- return __nolibc_enosys ( __func__ , fd , offset , whence ) ;
597- #endif
598- }
597+ __kernel_loff_t loff = 0 ;
598+ off_t result ;
599+ int ret ;
599600
600- static __attribute__((unused ))
601- int sys_llseek (int fd , unsigned long offset_high , unsigned long offset_low ,
602- __kernel_loff_t * result , int whence )
603- {
604- #if defined(__NR_llseek )
605- return my_syscall5 (__NR_llseek , fd , offset_high , offset_low , result , whence );
606- #else
607- return __nolibc_enosys (__func__ , fd , offset_high , offset_low , result , whence );
601+ /* Only exists on 32bit where nolibc off_t is also 32bit */
602+ ret = my_syscall5 (__NR_llseek , fd , 0 , offset , & loff , whence );
603+ if (ret < 0 )
604+ result = ret ;
605+ else if (loff != (off_t )loff )
606+ result = - EOVERFLOW ;
607+ else
608+ result = loff ;
609+
610+ return result ;
608611#endif
609612}
610613
611614static __attribute__((unused ))
612615off_t lseek (int fd , off_t offset , int whence )
613616{
614- __kernel_loff_t loff = 0 ;
615- off_t result ;
616- int ret ;
617-
618- result = sys_lseek (fd , offset , whence );
619- if (result == - ENOSYS ) {
620- /* Only exists on 32bit where nolibc off_t is also 32bit */
621- ret = sys_llseek (fd , 0 , offset , & loff , whence );
622- if (ret < 0 )
623- result = ret ;
624- else if (loff != (off_t )loff )
625- result = - EOVERFLOW ;
626- else
627- result = loff ;
628- }
629-
630- return __sysret (result );
617+ return __sysret (sys_lseek (fd , offset , whence ));
631618}
632619
633620
@@ -640,10 +627,8 @@ int sys_mkdir(const char *path, mode_t mode)
640627{
641628#if defined(__NR_mkdirat )
642629 return my_syscall3 (__NR_mkdirat , AT_FDCWD , path , mode );
643- #elif defined(__NR_mkdir )
644- return my_syscall2 (__NR_mkdir , path , mode );
645630#else
646- return __nolibc_enosys ( __func__ , path , mode );
631+ return my_syscall2 ( __NR_mkdir , path , mode );
647632#endif
648633}
649634
@@ -662,10 +647,8 @@ int sys_rmdir(const char *path)
662647{
663648#if defined(__NR_rmdir )
664649 return my_syscall1 (__NR_rmdir , path );
665- #elif defined(__NR_unlinkat )
666- return my_syscall3 (__NR_unlinkat , AT_FDCWD , path , AT_REMOVEDIR );
667650#else
668- return __nolibc_enosys ( __func__ , path );
651+ return my_syscall3 ( __NR_unlinkat , AT_FDCWD , path , AT_REMOVEDIR );
669652#endif
670653}
671654
@@ -685,10 +668,8 @@ long sys_mknod(const char *path, mode_t mode, dev_t dev)
685668{
686669#if defined(__NR_mknodat )
687670 return my_syscall4 (__NR_mknodat , AT_FDCWD , path , mode , dev );
688- #elif defined(__NR_mknod )
689- return my_syscall3 (__NR_mknod , path , mode , dev );
690671#else
691- return __nolibc_enosys ( __func__ , path , mode , dev );
672+ return my_syscall3 ( __NR_mknod , path , mode , dev );
692673#endif
693674}
694675
@@ -801,16 +782,14 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva
801782 t .tv_nsec = timeout -> tv_usec * 1000 ;
802783 }
803784 return my_syscall6 (__NR_pselect6 , nfds , rfds , wfds , efds , timeout ? & t : NULL , NULL );
804- #elif defined( __NR_pselect6_time64 )
785+ #else
805786 struct __kernel_timespec t ;
806787
807788 if (timeout ) {
808789 t .tv_sec = timeout -> tv_sec ;
809790 t .tv_nsec = timeout -> tv_usec * 1000 ;
810791 }
811792 return my_syscall6 (__NR_pselect6_time64 , nfds , rfds , wfds , efds , timeout ? & t : NULL , NULL );
812- #else
813- return __nolibc_enosys (__func__ , nfds , rfds , wfds , efds , timeout );
814793#endif
815794}
816795
@@ -874,10 +853,8 @@ int sys_symlink(const char *old, const char *new)
874853{
875854#if defined(__NR_symlinkat )
876855 return my_syscall3 (__NR_symlinkat , old , AT_FDCWD , new );
877- #elif defined(__NR_symlink )
878- return my_syscall2 (__NR_symlink , old , new );
879856#else
880- return __nolibc_enosys ( __func__ , old , new );
857+ return my_syscall2 ( __NR_symlink , old , new );
881858#endif
882859}
883860
@@ -931,10 +908,8 @@ int sys_unlink(const char *path)
931908{
932909#if defined(__NR_unlinkat )
933910 return my_syscall3 (__NR_unlinkat , AT_FDCWD , path , 0 );
934- #elif defined(__NR_unlink )
935- return my_syscall1 (__NR_unlink , path );
936911#else
937- return __nolibc_enosys ( __func__ , path );
912+ return my_syscall1 ( __NR_unlink , path );
938913#endif
939914}
940915
0 commit comments