pike.git / src / post_modules / Shuffler / a_source_pikestring.c

version» Context lines:

pike.git/src/post_modules/Shuffler/a_source_pikestring.c:13:         /* Source: String    * Argument: 8-bit string    */      struct ps_source   {    struct source s;    -  struct pike_string *str; -  int offset, len; +  struct pike_string*str; +  char *data; +  size_t len;   };      static struct data get_data( struct source *src, off_t len )   {    struct ps_source *s = (struct ps_source *)src;    struct data res;    -  res.data = s->str->str + s->offset; -  -  if( len > s->len ) -  { +  if( len > s->len ) {    len = s->len;    s->s.eof = 1; /* next read will be done from the next source */    }    -  res.len = len; +  res.data = s->data; +  s->data += len; +  s->len -= res.len = len;    -  s->len -= len; -  s->offset += len; -  +     return res;   }      static void free_source( struct source *src )   {    free_string(((struct ps_source *)src)->str);   }      struct source *source_pikestring_make( struct svalue *s,    INT64 start, INT64 len )   {    struct ps_source *res; -  +  INT64 slen;    -  if( TYPEOF(*s) != PIKE_T_STRING ) return 0; -  if( s->u.string->size_shift ) return 0; +  if (TYPEOF(*s) != PIKE_T_STRING +  || s->u.string->size_shift) +  return 0;    -  res = calloc( 1, sizeof( struct ps_source ) ); -  if( !res ) return NULL; -  debug_malloc_touch( res ); -  debug_malloc_touch( s ); +  if (!(res = calloc(1, sizeof(struct ps_source)))) +  return 0;    -  +  debug_malloc_touch(res); +     res->s.free_source = free_source;    res->s.get_data = get_data;       copy_shared_string(res->str, s->u.string); -  res->offset = start; +  res->data = res->str->str + start;    -  if( len != -1 ) -  { -  if( len > res->str->len-start ) -  { -  sub_ref(res->str); -  free(res); -  return 0; -  } -  else -  res->len = len; -  } -  else -  res->len = res->str->len-start; +  slen = res->str->len - start; +  if (len >= 0 && slen < len) +  slen = len; +  if (slen < 0) +  slen = 0;    -  if( res->len <= 0 ) -  { -  sub_ref(res->str); -  free(res); -  return 0; -  } +  res->len = slen;    return (struct source *)res;   }      void source_pikestring_init( )   {    /* nothing to do here */   }      void source_pikestring_exit( )   {    /* nothing to do here */   }