Changeset 3657:e6be7ef3fece in roaraudio


Ignore:
Timestamp:
04/03/10 11:45:32 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for dup() and dup2()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroaross/libroaross.c

    r3656 r3657  
    135135 off_t   (*lseek)(int fildes, off_t offset, int whence); 
    136136 FILE   *(*fopen)(const char *path, const char *mode); 
     137 int     (*dup)(int oldfd); 
     138 int     (*dup2)(int oldfd, int newfd); 
    137139} _os; 
    138140 
     
    180182 _os.lseek = dlsym(REAL_LIBC, "lseek"); 
    181183 _os.fopen = dlsym(REAL_LIBC, "fopen"); 
     184 _os.dup   = dlsym(REAL_LIBC, "dup"); 
     185 _os.dup2  = dlsym(REAL_LIBC, "dup2"); 
    182186} 
    183187 
     
    365369 
    366370 ret->handle = handle; 
     371 
     372 return ret; 
     373} 
     374 
     375static struct pointer * _attach_pointer(struct handle * handle, int fh) { 
     376 struct pointer * ret = _get_pointer_by_fh(-1); 
     377 
     378 if ( ret == NULL ) 
     379  return NULL; 
     380 
     381 if ( (ret->fh = fh) == -1 ) 
     382  return NULL; 
     383 
     384 ret->handle = handle; 
     385 
     386 handle->refc++; 
    367387 
    368388 return ret; 
     
    11441164} 
    11451165 
     1166int dup(int oldfd) { 
     1167 struct pointer * pointer; 
     1168 int ret; 
     1169 
     1170 _init(); 
     1171 
     1172 ret = _os.dup(oldfd); 
     1173 
     1174 if (ret == -1) 
     1175  return -1; 
     1176 
     1177 if ( (pointer = _get_pointer_by_fh(oldfd)) != NULL ) { 
     1178  if ( _attach_pointer(pointer->handle, ret) == NULL ) { 
     1179   _os.close(ret); 
     1180   return -1; 
     1181  } 
     1182 } 
     1183 
     1184 return ret; 
     1185} 
     1186 
     1187int dup2(int oldfd, int newfd) { 
     1188 struct pointer * pointer; 
     1189 int ret; 
     1190 
     1191 _init(); 
     1192 
     1193 ret = _os.dup2(oldfd, newfd); 
     1194 
     1195 if (ret == -1) 
     1196  return -1; 
     1197 
     1198 if ( (pointer = _get_pointer_by_fh(oldfd)) != NULL ) { 
     1199  if ( _attach_pointer(pointer->handle, ret) == NULL ) { 
     1200   _os.close(ret); 
     1201   return -1; 
     1202  } 
     1203 } 
     1204 
     1205 return ret; 
     1206} 
    11461207 
    11471208// ------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.