void basic_io_device::set_non_blocking(bool nonblocking,system::error_code &e) { #if defined BOOSTER_WIN32 unsigned long opt = nonblocking; if(::ioctlsocket(fd_,FIONBIO,&opt) < 0) e=geterror(); #elif ! defined(O_NONBLOCK) int opt = nonblocking; if(::ioctl(fd_,FIONBIO,&opt) < 0) e=geterror(); #else int flags = ::fcntl(fd_,F_GETFL,0); if(flags < 0) { e=geterror(); return; } if(nonblocking) flags = flags | O_NONBLOCK; else flags = flags & ~O_NONBLOCK; if(::fcntl(fd_,F_SETFL,flags) < 0) e=geterror(); #endif nonblocking_was_set_=nonblocking; }
char* CopyString(const char* str) { if (!OpenClipboard(NULL)) { return geterror("CopyString"); } // copy our UTF-8 text into a wchar string stored in the global handle size_t n = 0; mbstowcs_s(&n, NULL, 0, str, 0); // alloc and lock global memory HGLOBAL hMem = GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE, n*sizeof(wchar_t) + 1); LPTSTR glob = (LPTSTR)GlobalLock(hMem); mbstowcs_s(&n, glob, n + 1, str, n); GlobalUnlock(hMem); if (!SetClipboardData(CF_UNICODETEXT, hMem)) { return geterror("SetClipboardData"); } if (!CloseClipboard()) { return geterror("CloseClipboard"); } return NULL; }
static int scanpath (TCHAR *src, TCHAR *outpath) { struct zvolume *zv; struct zdirectory *h; TCHAR fn[MAX_DPATH]; zv = zfile_fopen_archive_root (src, ZFD_ALL | ZFD_NORECURSE); if (zv == NULL) { geterror(); _tprintf (_T("Couldn't open archive '%s'\n"), src); return 0; } h = zfile_opendir_archive (src); if (!h) { geterror(); _tprintf (_T("Couldn't open directory '%s'\n"), src); return 0; } while (zfile_readdir_archive (h, fn)) { TCHAR tmp[MAX_DPATH]; int isdir, flags; _tcscpy (tmp, src); _tcscat (tmp, sep); _tcscat (tmp, fn); zfile_fill_file_attrs_archive (tmp, &isdir, &flags, NULL); if (isdir == ZNODE_VDIR) { _tcscpy (outpath, tmp); scanpath (tmp, outpath); break; } } return 1; }
int do_wri(u8 * file){ s8 ret,fd; u32 retlba ; u8 i=0; u32 ch; u8 buff[256] = {0}; if (!check_for_args(WRI,1))return 1; fd = openf(file,O_RW); if ( fd == -1){ retlba=NO_LBA; if (ERROR_NO == NO_DIR_FILE) retlba = creatf(file , 064); if (retlba == NO_LBA){ vd_puts ( "COULD NOT OPEN OR CREATE THE DESTINATION FILE\n" ); errormessage(geterror()); closef(fd); fl_clean(); return 0; } fd = openf(file,O_RW); } if(fd == -1){ vd_puts("CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } while(1){ ch=getche(); if(ch == 1) break; if( ch == 13 || ch == 10){printf("\n"); ch = '\n';} if (i == 255){ i=0; ret = writef(fd,buff,256); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } } buff[i++] = ch; } ret = writef(fd,buff,i); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } closef(fd); vd_puts(" \n"); fl_clean(); return 0; }
int do_list(u8 * dir){ s8 fd,ret; struct fnode fn; int i; u8 size; struct dir_str dira[256]; u8 full_name[132];// fullpath name of child if (!check_for_args(LIST,1)) return 1; fd = opend(dir); if (fd == -1){ vd_puts("CANNOT OPEN DIRECTORY:: ");vd_puts(dir);vd_puts("\n"); errormessage(geterror()); fl_clean(); return 1; } ret = finfo(fd,&fn); if (ret == -1){ vd_puts(" CANNOT OPEN DIRECTORY::");vd_puts(dir);vd_puts("\n"); errormessage(geterror()); fl_clean(); return 1; } size = fn.ct_links; ret=readd(fd,size+2,dira); if (! ret){ vd_puts(" CANNOT READ THE DIRECTORY\n"); errormessage(geterror()); fl_clean(); return 2; } for(i=0; i < size+2 ; i++){ #ifdef COLOR_LIST strcpy(full_name,dir); strcat(full_name,"|"); strcat(full_name,dira[i].name); if ( !strcmp(dira[i].name,".") || ! strcmp(dira[i].name,"..") ){ textcolor(YELLOW); cprintf("%s\n\r",dira[i].name); textcolor(WHITE); continue; } if ( is_dir(full_name) ){ textcolor(YELLOW); cprintf("%s\n\r",dira[i].name); continue; } textcolor(BLUE); cprintf("%s\n\r",dira[i].name); #else printf("%s\n",dira[i].name); #endif } textcolor(WHITE); fl_clean(); return 0; }
int lo_server_join_multicast_group(lo_server s, const char *group) { struct ip_mreq mreq; unsigned int yes = 1; memset(&mreq, 0, sizeof(mreq)); #ifdef HAVE_INET_ATON if (inet_aton(group, &mreq.imr_multiaddr)==0) { int err = geterror(); lo_throw(s, err, strerror(err), "inet_aton()"); lo_server_free(s); return err; } #else mreq.imr_multiaddr.s_addr = inet_addr(group); if (mreq.imr_multiaddr.s_addr == INADDR_ANY || mreq.imr_multiaddr.s_addr == INADDR_NONE) { int err = geterror(); lo_throw(s, err, strerror(err), "inet_addr()"); lo_server_free(s); return err; } #endif mreq.imr_interface.s_addr=htonl(INADDR_ANY); if (setsockopt(s->sockets[0].fd,IPPROTO_IP,IP_ADD_MEMBERSHIP, &mreq,sizeof(mreq)) < 0) { int err = geterror(); lo_throw(s, err, strerror(err), "setsockopt(IP_ADD_MEMBERSHIP)"); lo_server_free(s); return err; } if (setsockopt(s->sockets[0].fd,SOL_SOCKET,SO_REUSEADDR, &yes,sizeof(yes)) < 0) { int err = geterror(); lo_throw(s, err, strerror(err), "setsockopt(SO_REUSEADDR)"); lo_server_free(s); return err; } #ifdef SO_REUSEPORT if (setsockopt(s->sockets[0].fd,SOL_SOCKET,SO_REUSEPORT, &yes,sizeof(yes)) < 0) { int err = geterror(); lo_throw(s, err, strerror(err), "setsockopt(SO_REUSEPORT)"); lo_server_free(s); return err; } #endif return 0; }
int do_app(u8 * file){ s8 ret,fd; u8 i=0; u32 ch; u8 buff[256]; struct fnode fn; u32 size; if (!check_for_args(APP,1)) return 1; fd = openf(file,O_RW); if(fd == -1){ vd_puts( "CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } finfo(fd, & fn); size = fn.size; ret= seekf(fd, size,SEEK_BEG); while(1){ ch=getche(); if(ch == 1) break; if (ch == 13 || ch == 10 ){ printf("\n");ch='\n'; } if (i == 255){ i=0; ret = writef(fd,buff,256); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } } buff[i++] = (u8)ch; } ret = writef(fd,buff,i); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } puts(" "); closef(fd); fl_clean(); return 0; }
int do_info(u8 * file){ struct fnode fn; s8 ret; if (!check_for_args(FINFO,1)) return 1; ret = info(file, &fn); if(ret == -1){ vd_puts("CANNOT GET INFO\n"); errormessage(geterror()); fl_clean(); return 1; } vd_puts("File :"); vd_puts(file);vd_puts("\n"); vd_puts("Size :"); vd_putint((unsigned int)fn.size);vd_puts("\n"); vd_puts("Links :"); vd_putint((unsigned int)fn.ct_links);vd_puts("\n"); vd_puts("m_time :");vd_putint((unsigned int)fn.m_time);vd_puts("\n"); vd_puts("User id :" );vd_putint( (unsigned int)fn.uid );vd_puts("\n"); vd_puts("mode :" ); vd_putint( (unsigned int)fn.mode );vd_puts("\n"); (fn.mode & 0x80 )? vd_puts("DIRECTORY") : vd_puts("ORDINARY FILE" ) ;vd_puts("\n"); vd_puts("PERMISSIONS :: \n" ); (fn.mode & OWNER_READ)? vd_puts("r"):vd_puts("-") ; (fn.mode & OWNER_WRITE)?vd_puts("w"):vd_puts("-") ; (fn.mode & OWNER_EXECUTE)?vd_puts("x"):vd_puts("-"); (fn.mode & OTHER_READ)?vd_puts("r"):vd_puts("-") ; (fn.mode & OTHER_WRITE)?vd_puts("w"):vd_puts("-") ; (fn.mode & OTHER_EXECUTE)?vd_puts("x"):vd_puts("-") ;vd_puts("\n"); fl_clean(); return 0; }
void basic_socket::open(family_type d,socket_type t,system::error_code &e) { int domain=0; switch(d) { case pf_unix: domain=AF_UNIX; break; case pf_inet: domain=AF_INET; break; case pf_inet6: domain = AF_INET6; break; } int type = 0; switch(t) { case sock_stream: type = SOCK_STREAM; break; case sock_datagram: type = SOCK_DGRAM; break; } { system::error_code etmp; close(etmp); } native_type fd = ::socket(domain,type,0); if(fd == invalid_socket) { e=geterror(); return; } assign(fd); }
void CommandParser::do_cd(){ int len; if (!is_loaded){ vd_puts("FILE SYSTEM NOT LOADED\n"); return ; } if(flpchange){ uloadfs(); } if ( strlen(first_arg) == 0){ vd_puts("Current Dir:"); vd_puts(curr_dir); return; } toAbsolute(first_arg); if ( ispresent(first_arg) == -1 ){ vd_puts( "THE DIRECTORY SEEMS TO BE ON A HOLIDAY !!\n" ); errormessage(geterror()); return; } if ( !is_dir(first_arg) ){ vd_puts( "The Specified File is not a directory\n" ); return; } strcpy(curr_dir,first_arg); }
bool basic_socket::get_option(boolean_option_type opt,system::error_code &e) { int value = 0; socklen_t len = sizeof(value); #ifdef BOOSTER_WIN32 char *ptr = reinterpret_cast<char *>(&value); #else int *ptr = &value; #endif int res = 0; switch(opt) { case tcp_no_delay: res=::getsockopt(native(),IPPROTO_TCP,TCP_NODELAY,ptr,&len); break; case keep_alive: res=::getsockopt(native(),SOL_SOCKET,SO_KEEPALIVE,ptr,&len); break; case reuse_address: res=::getsockopt(native(),SOL_SOCKET,SO_REUSEADDR,ptr,&len); break; default: ; } if(res < 0) { e=geterror(); return false; } return value!=0; }
int do_adduser(){ s8 ret; u32 i=0; u8 id; u8 password[PASSWORD_LENGTH] , ch; u8 username[MAX_NAME]; if (!check_for_args(ADDUSER,0)) return 1; vd_puts("ENTER USER NAME ::" ); gets(username); username[--i] = 0; i=0; vd_puts("\nENTER PASSWORD ::" ); while (i <= PASSWORD_LENGTH && (ch = password[i++] = getch()) != (u8)('\n') && ch != (u8)('\r'))vd_putchar('#'); password[--i] = 0; vd_puts("\n"); ret=useradd(username,password); if (ret == -1) { vd_puts("COULD NOT ADD USER\n"); errormessage(geterror()); fl_clean(); return 1; } fl_clean(); return 0; }
/** * @brief Write imgage. * @details Write compostied image to the file system. */ void writeImage() { // Transfer to something OpenImageIO understands oiioPixels.resize(newWidth*newHeight*4*sizeof(float)); for (int row = 0; row < newHeight; row++) for (int col = 0; col < newWidth; col++){ oiioPixels[(row*newWidth+col)*4 + 0] = warppedPixels[row][col].r; oiioPixels[(row*newWidth+col)*4 + 1] = warppedPixels[row][col].g; oiioPixels[(row*newWidth+col)*4 + 2] = warppedPixels[row][col].b; oiioPixels[(row*newWidth+col)*4 + 3] = warppedPixels[row][col].a; } // Create output image ImageOutput *out = ImageOutput::create(outImage); // Error handeling if (!out) { printf("Error writing image: %s\n", geterror().c_str()); exit(EXIT_FAILURE); } // Create output image spec ImageSpec spec (newWidth, newHeight, 4, TypeDesc::FLOAT); // Open output image file out->open(outImage, spec); // Write output image to disk and close out->write_image(TypeDesc::FLOAT, &oiioPixels[0]); out->close(); delete out; }
int do_show(u8 * file){ s8 fd, ret ; u32 i ; struct fnode fn; u32 size; u8 buff[1025]; if (!check_for_args(SHOW,1)) return 1; fd=openf(file,O_READ); if ( fd == -1){ vd_puts("CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } ret = finfo(fd,&fn); if ( ret == -1){ vd_puts("CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } size=fn.size; while(size){ ret = readf(fd,buff,(size < 1024 ? size : 1024)); if ( ret == -1){ vd_puts("CANNOT READ THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } buff[(size < 1024 ? size : 1024)]=0 ; for(i = 0 ; i < (size < 1024 ? size : 1024) ; ++i ) if ( buff[i] == 10 || buff[i] == 13) buff[i] = '\n'; vd_puts( buff); vd_puts("\n"); if (size >= 1024) size-=1024 ; else size=0; } closef(fd); fl_clean(); return 0; }
void stream_socket::connect(endpoint const &ep,system::error_code &e) { endpoint::native_address_type address = ep.raw(); #ifndef BOOSTER_WIN32 for(;;) { int res = ::connect(native(),address.first,address.second); if(res < 0 && errno==EINTR) continue; if(res < 0) { e=geterror(); return; } break; } #else if(::connect(native(),address.first,address.second) < 0) e=geterror(); #endif }
int do_rf(u8 * file){ s8 ret; if (!check_for_args(RF,1)) return 1; ret = unlinkf(file); if(ret == -1){ vd_puts("CANNOT REMOVE THE FILE\n"); errormessage(geterror()); } fl_clean(); return 0; }
int do_ren(u8 * _old , u8 * _new){ s8 ret; if (!check_for_args(REN,2)) return 1; ret =ren(_old, _new); if(ret == -1){ vd_puts("CANNOT RENAME THIS FILE\n"); errormessage(geterror()); } fl_clean(); return 0; }
void is_file(const char *filename) { FILE *fp; if((fp = fopen(filename, "r")) == NULL) { geterror("Can't open %s for read", filename); die(); } }
int do_rmd(u8 * dir){ s8 ret; if (!check_for_args(RMD,1)) return 1; ret= removed(dir); if(ret == -1){ vd_puts("CANNOT REMOVE THIS DIRECTORY\n"); errormessage(geterror()); } fl_clean(); return 0; }
endpoint basic_socket::remote_endpoint(system::error_code &e) { std::vector<char> endpoint_raw_(1000,0); sockaddr *sa = reinterpret_cast<sockaddr *>(&endpoint_raw_.front()); socklen_t len = endpoint_raw_.size(); if(::getpeername(native(),sa,&len) < 0) e=geterror(); endpoint ep; ep.raw(sa,len); return ep; }
int do_link(u8 * file , u8 * link){ s8 ret; if (!check_for_args(LINK,2)) return 1; ret = linkf(file,link); if(ret == -1){ vd_puts("CANNOT CREATE LINK\n"); errormessage(geterror()); } fl_clean(); return 0; }
void Connector::init(string host, string port, string user, string password, string db) { #ifdef MSSQL login_rec = NULL; conn_ptr = NULL; dberrhandle (err_handler); dbmsghandle (msg_handler); conn_status = false; cout << "init db connectors.. " << endl; init_db_connectors(); if(conn_status){ set_login_struct(user , password); cout << "added login credentials to struct.. " << endl; if (conn_status){ cout << "connecting to db..." << db << endl; connect_to_db(host , port); if (conn_status){ choose_db(db); } else { cout << "geterror: " << geterror() << endl; } } else { cout << "geterror: " << geterror() << endl; } } else { cout << "geterror: " << geterror() << endl; } #endif #ifdef WATCHLIST_MYSQL cout << "Connecting to mysql db.. " << endl; conn_status = true; mysql_init(&mysqlID); mysql_options(&mysqlID, MYSQL_OPT_RECONNECT, (char *)&conn_status); mysql_real_connect(&mysqlID, host.c_str(), user.c_str(), password.c_str(), db.c_str(), 0, NULL, CLIENT_COMPRESS | CLIENT_MULTI_RESULTS | CLIENT_MULTI_STATEMENTS); #endif }
P op_errormessage(void) { LBIG e, pid, port; P nb, tnb; B *m, *s; if (o_6 < FLOORopds) goto baderror; if (CLASS(o_6) != NUM) goto baderror; if (! VALUE(o_6, &pid)) goto baderror; if (TAG(o_5) != (ARRAY | BYTETYPE)) goto baderror; if (CLASS(o_4) != NUM) goto baderror; if (! VALUE(o_4, &port)) goto baderror; if (TAG(o_3) != (ARRAY | BYTETYPE)) goto baderror; if (CLASS(o_2) != NUM) goto baderror; if (!VALUE(o_2, &e)) goto baderror; if (TAG(o_1) != (ARRAY | BYTETYPE)) goto baderror; s = (B *)VALUE_BASE(o_1); tnb = ARRAY_SIZE(o_1); nb = dm_snprintf((char*) s, tnb, "On %*s port %llu, pid %llu: ", (int) ARRAY_SIZE(o_5), (char*) VALUE_BASE(o_5), (unsigned long long) port, (unsigned long long) pid); s += nb; tnb -= nb; if ((P)e < 0) /*Clib error */ nb = dm_snprintf((char*) s, tnb, "errno: %s", (char*) strerror(-(int)e)); else { /* one of our error codes: decode */ m = geterror((P) e); nb = strlen((char*) m); if (nb > tnb) nb = tnb; moveB(m, s, nb); } s += nb; tnb -= nb; nb = dm_snprintf((char*)s, tnb, " in %*s\n", (int) ARRAY_SIZE(o_3), (char*) VALUE_BASE(o_3)); ARRAY_SIZE(o_1) = (P)(s + nb) - VALUE_BASE(o_1); moveframe(o_1,o_6); FREEopds = o_5; return OK; baderror: printf("**Error with corrupted error info on operand stack!\n"); return op_halt(); }
size_t stream_socket::read_some(mutable_buffer const &buffer,system::error_code &e) { int n=readv(buffer); if(n < 0) { e=geterror(); return 0; } if(n == 0) { e=system::error_code(aio_error::eof,aio_error_cat); return 0; } return n; }
/* * Implements the interrupt side for file vdev types. This routine will be * called when the I/O completes allowing us to transfer the I/O to the * interrupt taskqs. For consistency, the code structure mimics disk vdev * types. */ static void vdev_file_io_intr(buf_t *bp) { vdev_buf_t *vb = (vdev_buf_t *)bp; zio_t *zio = vb->vb_io; zio->io_error = (geterror(bp) != 0 ? EIO : 0); if (zio->io_error == 0 && bp->b_resid != 0) zio->io_error = ENOSPC; kmem_free(vb, sizeof (vdev_buf_t)); zio_interrupt(zio); }
int do_chperm(u8 * path , u8 * newperm){ s8 ret; u8 own; if (!check_for_args(CHPERM,1)) return 1; own = (u8)atoi((char *)newperm); ret = chperm(path,own); if (ret == -1){ vd_puts ( "COULD NOT CHANGE PERMISSION\n"); errormessage(geterror()); } fl_clean(); return 0; }
size_t stream_socket::write_some(const_buffer const &buffer,system::error_code &e) { int n=writev(buffer); if(n < 0) { e=geterror(); return 0; } if(n == 0) { e=system::error_code(aio_error::eof,aio_error_cat); return 0; } return n; }
int dadk_flushdone(struct buf *bp) { struct dk_callback *dkc = bp->b_private; ASSERT(dkc != NULL && dkc->dkc_callback != NULL); (*dkc->dkc_callback)(dkc->dkc_cookie, geterror(bp)); kmem_free(dkc, sizeof (*dkc)); freerbuf(bp); return (0); }
void basic_io_device::close(system::error_code &e) { if(fd_ == invalid_socket) return; if(has_io_service()) cancel(); if(!owner_) return; if(close_file_descriptor(fd_)) e=geterror(); fd_ = invalid_socket; nonblocking_was_set_ = false; }
int main(int argc, char **argv) { char *path, *args, *reply; uint64_t ctrl; int i; if (argc < 2) { fprintf(stderr, "%s: missing operand\n", argv[0]); return 1; } if (argv[1][0] == '/') { path = strdup(argv[1]); } else if (argv[1][0] == '@') { path = strdup(argv[1]); } else { path = strvcat("/sys/", argv[1]); } ctrl = fs_find(path); if (!ctrl) { fprintf(stderr, "%s: %s: control file not accessible\n", argv[0], path); return 1; } args = malloc(1000); args[0] = '\0'; for (i = 2; i < argc; i++) { strlcat(args, argv[i], 1000); strlcat(args, " ", 1000); } if (args[0]) args[strlen(args)-1] = '\0'; reply = rcall(ctrl, args); if (!reply) { printf("! nosys (not implemented)\n"); return 1; } if (iserror(reply)) { printf("%s (%s)\n", reply, strerror(geterror(reply))); } else { printf("%s\n", reply); } return 0; }