Changeset 3264:e38f65edb159 in roaraudio for libroaross


Ignore:
Timestamp:
01/31/10 15:00:07 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support for fopen()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroaross/libroaross.c

    r3261 r3264  
    133133#endif 
    134134 off_t   (*lseek)(int fildes, off_t offset, int whence); 
     135 FILE   *(*fopen)(const char *path, const char *mode); 
    135136} _os; 
    136137 
     
    177178#endif 
    178179 _os.lseek = dlsym(REAL_LIBC, "lseek"); 
     180 _os.fopen = dlsym(REAL_LIBC, "fopen"); 
    179181} 
    180182 
     
    11121114} 
    11131115 
     1116 
     1117// ------------------------------------- 
     1118// emulated stdio functions follow: 
     1119// ------------------------------------- 
     1120 
     1121//roar_vio_to_stdio 
     1122 
     1123FILE *fopen(const char *path, const char *mode) { 
     1124 struct pointer * pointer; 
     1125 FILE  * fr; 
     1126 int     ret; 
     1127 int     r = 0, w = 0; 
     1128 int     flags = 0; 
     1129 int     i; 
     1130 register char c; 
     1131 
     1132 _init(); 
     1133 
     1134 if ( path == NULL || mode == NULL ) { 
     1135  errno = EFAULT; 
     1136  return NULL; 
     1137 } 
     1138 
     1139 ROAR_DBG("open(pathname='%s', mode='%s') = ?\n", pathname, mode); 
     1140 
     1141 for (i = 0; (c = mode[i]) != 0; i++) { 
     1142  switch (c) { 
     1143   case 'r': r = 1; break; 
     1144   case 'w': w = 1; break; 
     1145   case 'a': w = 1; break; 
     1146   case '+': 
     1147     r = 1; 
     1148     w = 1; 
     1149    break; 
     1150  } 
     1151 } 
     1152 
     1153 if ( r && w ) { 
     1154  flags = O_RDWR; 
     1155 } else if ( r ) { 
     1156  flags = O_RDONLY; 
     1157 } else if ( w ) { 
     1158  flags = O_WRONLY; 
     1159 } else { 
     1160  errno = EINVAL; 
     1161  return NULL; 
     1162 } 
     1163 
     1164 ret = _open_file(path, flags); 
     1165 
     1166 switch (ret) { 
     1167  case -2:       // continue as normal, use _op.open() 
     1168   break; 
     1169  case -1:       // pass error to caller 
     1170    return NULL; 
     1171   break; 
     1172  default:       // return successfully opened pointer to caller 
     1173    if ( (pointer = _get_pointer_by_fh(ret)) != NULL ) { 
     1174     if ( (fr = roar_vio_to_stdio(&(pointer->handle->stream_vio), flags)) == NULL ) { 
     1175      errno = EIO; 
     1176      return NULL; 
     1177     } else { 
     1178      return fr; 
     1179     } 
     1180    } else { 
     1181     errno = EIO; 
     1182     return NULL; 
     1183    } 
     1184   break; 
     1185 } 
     1186 
     1187 return _os.fopen(path, mode); 
     1188} 
     1189 
    11141190#endif 
    11151191 
Note: See TracChangeset for help on using the changeset viewer.