pike.git / src / modules / _Stdio / file.c

version» Context lines:

pike.git/src/modules/_Stdio/file.c:1385:    if(FD < 0)    Pike_error("File not open.\n");       if(!args)    {    len=0x7fffffff;    }    else    {    if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("read", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("read", 1, "int");    len=Pike_sp[-args].u.integer;    if(len<0)    Pike_error("Cannot read negative number of characters.\n");    if (!len && SUBTYPEOF(Pike_sp[-args])) {    len = 0x7fffffff;    }    }       if(args > 1 && !UNSAFE_IS_ZERO(Pike_sp+1-args))    {
pike.git/src/modules/_Stdio/file.c:1657:    if(FD < 0)    Pike_error("File not open.\n");       if(!args)    {    len=0x7fffffff;    }    else    {    if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("read_oob", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("read_oob", 1, "int");    len=Pike_sp[-args].u.integer;    if(len<0)    Pike_error("Cannot read negative number of characters.\n");    }       if(args > 1 && !UNSAFE_IS_ZERO(Pike_sp+1-args))    {    all=0;    }else{    all=1;
pike.git/src/modules/_Stdio/file.c:1869:    *! @seealso    *! @[read()], @[write_oob()], @[send_fd()]    */   static void file_write(INT32 args)   {    ptrdiff_t written, i;    struct pike_string *str;       if(args<1 || ((TYPEOF(Pike_sp[-args]) != PIKE_T_STRING) &&    (TYPEOF(Pike_sp[-args]) != PIKE_T_ARRAY))) -  SIMPLE_BAD_ARG_ERROR("write", 1, "string|array(string)"); +  SIMPLE_ARG_TYPE_ERROR("write", 1, "string|array(string)");       if(FD < 0)    Pike_error("File not open for write.\n");       if (TYPEOF(Pike_sp[-args]) == PIKE_T_ARRAY) {    struct array *a = Pike_sp[-args].u.array;       if( (a->type_field & ~BIT_STRING) &&    (array_fix_type_field(a) & ~BIT_STRING) ) -  SIMPLE_BAD_ARG_ERROR("write", 1, "string|array(string)"); +  SIMPLE_ARG_TYPE_ERROR("write", 1, "string|array(string)");       i = a->size;    while(i--)    if (a->item[i].u.string->size_shift)    Pike_error("Bad argument 1 to file->write().\n"    "Element %ld is a wide string.\n",    (long)i);      #ifdef HAVE_WRITEV    if (args > 1) {
pike.git/src/modules/_Stdio/file.c:2184:    *!    *! @seealso    *! @[read_oob()], @[write()]    */   static void file_write_oob(INT32 args)   {    ptrdiff_t written, i;    struct pike_string *str;       if(args<1 || TYPEOF(Pike_sp[-args]) != PIKE_T_STRING) -  SIMPLE_BAD_ARG_ERROR("write_oob",1,"string"); +  SIMPLE_ARG_TYPE_ERROR("write_oob",1,"string");       if(args > 1)    {    f_sprintf(args);    args=1;    }       if(FD < 0)    Pike_error("File not open for write_oob.\n");   
pike.git/src/modules/_Stdio/file.c:2294: Inside #if defined(HAVE_PIKE_SEND_FD)
  static void file_send_fd(INT32 args)   {    int other_fd;    struct object *o = NULL;    struct my_file *f = NULL;    int *fd_info = NULL;       if(args<1 || (TYPEOF(Pike_sp[-args]) != PIKE_T_OBJECT) ||    !(o = Pike_sp[-args].u.object)->prog ||    (o->prog->inherits[SUBTYPEOF(Pike_sp[-args])].prog != file_program)) -  SIMPLE_BAD_ARG_ERROR("send_fd", 1, "Stdio.Fd"); +  SIMPLE_ARG_TYPE_ERROR("send_fd", 1, "Stdio.Fd");       f = (struct my_file *)    (o->storage + o->prog->inherits[SUBTYPEOF(Pike_sp[-args])].storage_offset);       if (f->box.fd == -1) {    Pike_error("Bad argument 1 to Stdio.File->send_fd(): "    "File descriptor not open.\n");    }       if(FD < 0)
pike.git/src/modules/_Stdio/file.c:2392: Inside #if defined(SO_LINGER)
   int fd = FD;    int linger = -1;    struct linger li;       if(fd < 0)    Pike_error("File not open.\n");       get_all_args("linger", args, ".%d", &linger);       if ((linger < -1) || (linger > 0xffff)) { -  SIMPLE_BAD_ARG_ERROR("linger", 1, "int(-1..65535)"); +  SIMPLE_ARG_TYPE_ERROR("linger", 1, "int(-1..65535)");    }       if (linger == -1) {    li.l_onoff = 0;    li.l_linger = 15;    } else {    li.l_onoff = 1;    li.l_linger = linger;    }   
pike.git/src/modules/_Stdio/file.c:2678:    int access;    int err;    struct pike_string *str, *flag_str;    close_fd();       if(args < 2)    SIMPLE_TOO_FEW_ARGS_ERROR("open", 2);       if(TYPEOF(Pike_sp[-args]) != PIKE_T_STRING &&    TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("open", 1, "string|int"); +  SIMPLE_ARG_TYPE_ERROR("open", 1, "string|int");       if(TYPEOF(Pike_sp[1-args]) != PIKE_T_STRING) -  SIMPLE_BAD_ARG_ERROR("open", 2, "string"); +  SIMPLE_ARG_TYPE_ERROR("open", 2, "string");       if (args > 2)    {    if (TYPEOF(Pike_sp[2-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("open", 3, "int"); +  SIMPLE_ARG_TYPE_ERROR("open", 3, "int");    access = Pike_sp[2-args].u.integer;    } else    access = 00666;       flags = parse((flag_str = Pike_sp[1-args].u.string)->str);       if (TYPEOF(Pike_sp[-args]) == PIKE_T_STRING)    {    str=Pike_sp[-args].u.string;   
pike.git/src/modules/_Stdio/file.c:2837: Inside #if !defined(__NT__) && (defined(HAVE_POSIX_OPENPT) || defined(PTY_MASTER_PATHNAME)) and #if defined(HAVE_POSIX_OPENPT)
   int flags,fd;   #ifdef HAVE_POSIX_OPENPT    struct pike_string *flag_str;   #endif    close_fd();       if(args < 1)    SIMPLE_TOO_FEW_ARGS_ERROR("openpt", 2);       if(TYPEOF(Pike_sp[-args]) != PIKE_T_STRING) -  SIMPLE_BAD_ARG_ERROR("openpt", 1, "string"); +  SIMPLE_ARG_TYPE_ERROR("openpt", 1, "string");      #ifdef HAVE_POSIX_OPENPT    flags = parse((flag_str = Pike_sp[-args].u.string)->str);       if(!( flags & (FILE_READ | FILE_WRITE)))    Pike_error("Must open file for at least one of read and write.\n");       do {    THREADS_ALLOW_UID();    fd=posix_openpt(map(flags));
pike.git/src/modules/_Stdio/file.c:3043:    SIMPLE_TOO_FEW_ARGS_ERROR("seek", 1);      #if defined (SEEK64)    if(is_bignum_object_in_svalue(&Pike_sp[-args])) {    if (!int64_from_bignum(&to, Pike_sp[-args].u.object))    Pike_error ("Bad argument 1 to Stdio.File->seek(). Offset too large.\n");    }    else   #endif    if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("seek", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("seek", 1, "int");    else    to=Pike_sp[-args].u.integer;       if(FD < 0)    Pike_error("File not open.\n");          if( args == 2 && TYPEOF(Pike_sp[-args+1]) == PIKE_T_STRING )    {    how = Pike_sp[-args+1].u.string->str[0];    }    else    {    if(args>1)    {    if(TYPEOF(Pike_sp[-args+1]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("seek", 2, "int"); +  SIMPLE_ARG_TYPE_ERROR("seek", 2, "int");    to *= Pike_sp[-args+1].u.integer;    }    if(args>2)    {    if(TYPEOF(Pike_sp[-args+2]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("seek", 3, "int"); +  SIMPLE_ARG_TYPE_ERROR("seek", 3, "int");    to += Pike_sp[-args+2].u.integer;    }       if( to < 0 )    how = SEEK_END;    }    ERRNO=0;      #if defined(HAVE_LSEEK64) && !defined(__NT__)    to = lseek64(FD,to,how);
pike.git/src/modules/_Stdio/file.c:3156: Inside #if defined (INT64) and #if defined (HAVE_FTRUNCATE64) || SIZEOF_OFF_T > SIZEOF_INT_TYPE
  #if defined (INT64)   #if defined (HAVE_FTRUNCATE64) || SIZEOF_OFF_T > SIZEOF_INT_TYPE    if(is_bignum_object_in_svalue(&Pike_sp[-args])) {    if (!int64_from_bignum(&len, Pike_sp[-args].u.object))    Pike_error ("Bad argument 1 to Stdio.File->truncate(). Length too large.\n");    }    else   #endif   #endif    if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("truncate", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("truncate", 1, "int");    else    len = Pike_sp[-args].u.integer;       if(FD < 0)    Pike_error("File not open.\n");       ERRNO=0;   #ifdef HAVE_FTRUNCATE64    res = ftruncate64 (FD, len);   #else
pike.git/src/modules/_Stdio/file.c:3730:    *! @[query_backend], @[set_nonblocking], @[set_read_callback], @[set_write_callback], @[set_fs_event_callback]    */   static void file_set_backend (INT32 args)   {    struct my_file *f = THIS;    struct Backend_struct *backend;       if (!args)    SIMPLE_TOO_FEW_ARGS_ERROR ("set_backend", 1);    if (TYPEOF(Pike_sp[-args]) != PIKE_T_OBJECT) -  SIMPLE_BAD_ARG_ERROR ("set_backend", 1, "Pike.Backend"); +  SIMPLE_ARG_TYPE_ERROR ("set_backend", 1, "Pike.Backend");    backend = get_storage (Pike_sp[-args].u.object, Backend_program);    if (!backend) -  SIMPLE_BAD_ARG_ERROR ("set_backend", 1, "Pike.Backend"); +  SIMPLE_ARG_TYPE_ERROR ("set_backend", 1, "Pike.Backend");       /* FIXME: Only allow set_backend() if the file is open? */      #ifdef __NT__    if ((THIS->box.fd >= 0) &&    !(fd_query_properties(THIS->box.fd, fd_CAN_NONBLOCK) & fd_CAN_NONBLOCK)) {    Pike_error("set_backend() on non-socket!\n");    }   #endif /* __NT__ */   
pike.git/src/modules/_Stdio/file.c:3909:    *! @[close] is called.    *!    *! @seealso    *! @[release_fd()]    */   static void file_take_fd(INT32 args)   {    if (args < 1)    SIMPLE_TOO_FEW_ARGS_ERROR ("take_fd", 1);    if (TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR ("take_fd", 0, "int"); +  SIMPLE_ARG_TYPE_ERROR ("take_fd", 0, "int");    change_fd_for_box(&THIS->box, Pike_sp[-args].u.integer);   }      PMOD_EXPORT struct object *file_make_object_from_fd(int fd, int mode, int guess)   {    struct object *o;    struct my_file *f;    if (Pike_fp->context->prog == file_program) {    /* Called from within the file (aka Fd) object.    * Attempt to clone ourselves.
pike.git/src/modules/_Stdio/file.c:4015:   static void file_set_buffer(INT32 args)   {    INT32 bufsize;    int flags;       if(FD==-1)    Pike_error("Stdio.File->set_buffer() on closed file.\n");    if(!args)    SIMPLE_TOO_FEW_ARGS_ERROR("set_buffer", 1);    if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("set_buffer", 1, "int"); +  SIMPLE_ARG_TYPE_ERROR("set_buffer", 1, "int");       bufsize=Pike_sp[-args].u.integer;    if(bufsize < 0)    Pike_error("Bufsize must be larger than zero.\n");       if(args>1)    {    if(TYPEOF(Pike_sp[1-args]) != PIKE_T_STRING) -  SIMPLE_BAD_ARG_ERROR("set_buffer", 2, "string"); +  SIMPLE_ARG_TYPE_ERROR("set_buffer", 2, "string");    flags=parse(Pike_sp[1-args].u.string->str);    }else{    flags=FILE_READ | FILE_WRITE;    }      #ifdef SOCKET_BUFFER_MAX   #if SOCKET_BUFFER_MAX    if(bufsize>SOCKET_BUFFER_MAX) bufsize=SOCKET_BUFFER_MAX;   #endif    flags &= THIS->open_mode;
pike.git/src/modules/_Stdio/file.c:4554:    struct object *o;    struct my_file *fd;       if(args < 1)    SIMPLE_TOO_FEW_ARGS_ERROR("dup2", 1);       if(FD < 0)    Pike_error("File not open.\n");       if(TYPEOF(Pike_sp[-args]) != PIKE_T_OBJECT) -  SIMPLE_BAD_ARG_ERROR("dup2", 1, "Stdio.File"); +  SIMPLE_ARG_TYPE_ERROR("dup2", 1, "Stdio.File");       o=Pike_sp[-args].u.object;       fd=get_file_storage(o);       if(!fd) -  SIMPLE_BAD_ARG_ERROR("dup2", 1, "Stdio.File"); +  SIMPLE_ARG_TYPE_ERROR("dup2", 1, "Stdio.File");       if(fd->box.fd < 0) {    int new_fd;    if((new_fd = fd_dup(FD)) < 0)    {    ERRNO = errno;    pop_n_elems(args);    push_int(0);    return;    }
pike.git/src/modules/_Stdio/file.c:4667:       if (args) {    PIKE_SOCKADDR addr;    int addr_len;    char *name;    int o;       if (TYPEOF(Pike_sp[-args]) != PIKE_T_INT &&    (TYPEOF(Pike_sp[-args]) != PIKE_T_STRING ||    Pike_sp[-args].u.string->size_shift)) { -  SIMPLE_BAD_ARG_ERROR("open_socket", 1, "int|string(8bit)"); +  SIMPLE_ARG_TYPE_ERROR("open_socket", 1, "int|string(8bit)");    }    if (args > 1 && !UNSAFE_IS_ZERO(&Pike_sp[1-args])) {    if (TYPEOF(Pike_sp[1-args]) != PIKE_T_STRING) { -  SIMPLE_BAD_ARG_ERROR("open_socket", 2, "string"); +  SIMPLE_ARG_TYPE_ERROR("open_socket", 2, "string");    }       name = Pike_sp[1-args].u.string->str;    } else {    name = NULL;    }    addr_len = get_inet_addr(&addr, name,    (TYPEOF(Pike_sp[-args]) == PIKE_T_STRING?    Pike_sp[-args].u.string->str : NULL),    (TYPEOF(Pike_sp[-args]) == PIKE_T_INT?
pike.git/src/modules/_Stdio/file.c:4989:    get_all_args("connect", args, "%S%*", &dest_addr, &dest_port);    }    else if( args == 5 )    {    struct svalue *src_sv;    get_all_args("connect", args, "%S%*%*%*%S",    &dest_addr, &dest_port, &src_sv, &src_port, &data);    if(TYPEOF(*src_sv) != PIKE_T_INT )    {    if (TYPEOF(*src_sv) != PIKE_T_STRING || src_sv->u.string->size_shift) -  SIMPLE_BAD_ARG_ERROR("connect", 3, "int|string(8bit)"); +  SIMPLE_ARG_TYPE_ERROR("connect", 3, "int|string(8bit)");    src_addr = src_sv->u.string;    }    } else {    get_all_args("connect", args, "%S%*%S%*",    &dest_addr, &dest_port, &src_addr, &src_port);    }       if(TYPEOF(*dest_port) != PIKE_T_INT &&    (TYPEOF(*dest_port) != PIKE_T_STRING || dest_port->u.string->size_shift)) -  SIMPLE_BAD_ARG_ERROR("connect", 2, "int|string(8bit)"); +  SIMPLE_ARG_TYPE_ERROR("connect", 2, "int|string(8bit)");       if(src_port && TYPEOF(*src_port) != PIKE_T_INT &&    (TYPEOF(*src_port) != PIKE_T_STRING || src_port->u.string->size_shift)) -  SIMPLE_BAD_ARG_ERROR("connect", 4, "int|string(8bit)"); +  SIMPLE_ARG_TYPE_ERROR("connect", 4, "int|string(8bit)");      /* fprintf(stderr, "connect: family: %d\n", SOCKADDR_FAMILY(addr)); */       addr_len = get_inet_addr(&addr, dest_addr->str,    (TYPEOF(*dest_port) == PIKE_T_STRING?    dest_port->u.string->str : NULL),    (TYPEOF(*dest_port) == PIKE_T_INT?    dest_port->u.integer : -1), 0);    INVALIDATE_CURRENT_TIME();   
pike.git/src/modules/_Stdio/file.c:5257:    *! See @[open()].    *!    *! @seealso    *! @[open()]    */   static void file_create(INT32 args)   {    if(!args) return;    if(TYPEOF(Pike_sp[-args]) != PIKE_T_STRING &&    TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("create", 1, "int|string"); +  SIMPLE_ARG_TYPE_ERROR("create", 1, "int|string");       close_fd();    file_open(args);   }      #ifdef _REENTRANT      struct new_thread_data   {    INT32 from, to;
pike.git/src/modules/_Stdio/file.c:5335: Inside #if defined(_REENTRANT)
  void file_proxy(INT32 args)   {    struct my_file *f;    struct new_thread_data *p;    int from, to;       THREAD_T id;    check_all_args("Stdio.File->proxy",args, BIT_OBJECT,0);    f=get_file_storage(Pike_sp[-args].u.object);    if(!f) -  SIMPLE_BAD_ARG_ERROR("proxy", 1, "Stdio.File"); +  SIMPLE_ARG_TYPE_ERROR("proxy", 1, "Stdio.File");       from=fd_dup(f->box.fd);    if(from<0)    {    ERRNO=errno;    Pike_error("Failed to dup proxy fd. (errno=%d)\n",errno);    }    to=fd_dup(FD);    if(to<0)    {
pike.git/src/modules/_Stdio/file.c:5917:   /* void file_tcsetpgrp(INT32 args); */   #endif      static void fd__sprintf(INT32 args)   {    INT_TYPE type;       if(args < 1)    SIMPLE_TOO_FEW_ARGS_ERROR("_sprintf",2);    if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT) -  SIMPLE_BAD_ARG_ERROR("_sprintf",0,"int"); +  SIMPLE_ARG_TYPE_ERROR("_sprintf",0,"int");       type = Pike_sp[-args].u.integer;    pop_n_elems(args);    switch( type )    {    case 'O':    {    /* NB: A signed 64-bit int maxes out at 21 characters. */    char buf[30];    sprintf (buf, "Fd(%ld)", (long)FD);