unichar_t *u_GFileNormalize(unichar_t *name) { unichar_t *pt, *base, *ppt; if ( (pt = uc_strstr(name,"://"))!=NULL ) { base = u_strchr(pt+3,'/'); if ( base==NULL ) return( name ); ++base; } else if ( *name=='/' ) base = name+1; else base = name; for ( pt=base; *pt!='\0'; ) { if ( *pt=='/' ) u_strcpy(pt,pt+1); else if ( uc_strncmp(pt,"./",2)==0 ) u_strcpy(pt,pt+2); else if ( uc_strncmp(pt,"../",2)==0 ) { for ( ppt=pt-2; ppt>=base && *ppt!='/'; --ppt ); ++ppt; if ( ppt>=base ) { u_strcpy(ppt,pt+3); pt = ppt; } else pt += 3; } else { while ( *pt!='/' && *pt!='\0' ) ++pt; if ( *pt == '/' ) ++pt; } } return( name ); }
static int AddProtocol(unichar_t *prefix,int len) { if ( plen>=pmax ) { pmax += 20; /* We're never going to support 20 protocols? */ if ( plen==0 ) { protocols = (struct protocols *) galloc(pmax*sizeof(struct protocols)); } else { protocols = (struct protocols *) grealloc(protocols,pmax*sizeof(struct protocols)); } } memset(protocols+plen,0,sizeof(struct protocols)); if ( uc_strncmp(prefix,"file",len)==0 ) { protocols[plen].handle = NULL; protocols[plen].dispatcher = _GIO_fileDispatch; protocols[plen].cancel = NULL; protocols[plen].term = NULL; protocols[plen].dothread = false; } else { return( false ); } protocols[plen].index = plen; protocols[plen].proto = u_copyn(prefix,len); ++plen; return( true ); }