STATUS s_srem_set() { char *s; char *send; i4 pos; i4 n; char short_remark[OOSHORTREMSIZE+1]; if (St_sr_given) { s_error(0x3A8, NONFATAL, NULL); s_cmd_skip(); return FAIL; } if (Cact_ren == NULL) { s_error(0x38A, FATAL, NULL); } St_sr_given = TRUE; Tokchar++; while (CMspace(Tokchar) || *Tokchar == '\t') { CMnext(Tokchar); } s = short_remark; send = s + OOSHORTREMSIZE; while (*Tokchar != '\n' && *Tokchar != EOS) { if (s <= send-CMbytecnt(Tokchar)) { if (*Tokchar == '\t') { /* if tab, replace it with the one blank */ *s = ' '; s++; Tokchar++; } else { CMcpyinc(Tokchar, s); } } else { CMnext(Tokchar); } } *s = EOS; Cact_ren->ren_shortrem = STalloc(short_remark); return OK; }
/** * Let sleepers know about the wake-up condition. * * @param hl the list of waiting parties * @param data waking-up data to supply to callback */ static void wq_notify(hash_list_t *hl, void *data) { hash_list_iter_t *iter; size_t i, count; iter = hash_list_iterator(hl); count = hash_list_length(hl); i = 0; while (hash_list_iter_has_next(iter)) { wq_event_t *we = hash_list_iter_next(iter); wq_status_t status; wq_event_check(we); /* * Stop iteration in case callbacks have called wq_sleep() on the * same waiting queue we're iterating on and added items to the list. * This sanity check ensures we're not going to loop forever with a * callback systematically appending something. */ if (i++ >= count) { /* Something is odd, let them know about the calling stack */ s_critical("stopping after processing %zu item%s (list now has %u)", count, plural(count), hash_list_length(hl)); } status = (*we->cb)(we->arg, data); switch (status) { case WQ_SLEEP: continue; /* Still sleeping, leave in the list */ case WQ_EXCLUSIVE: case WQ_REMOVE: goto remove; } s_error("invalid status %d returned by %s()", status, stacktrace_function_name(we->cb)); remove: hash_list_iter_remove(iter); wq_event_free(we); /* * The callback may decide that we shouldn't continue notifying * other sleepers (because it knows it grabbed a resource that others * will need for instance). This is used as an early termination * of the loop. */ if (WQ_EXCLUSIVE == status) break; } hash_list_iter_release(&iter); }
/** * Initialize the LRU page cache with default values. */ void lru_init(DBM *db) { g_assert(NULL == db->cache); g_assert(-1 == db->pagbno); /* We must be called before first access */ if (-1 == init_cache(db, LRU_PAGES, FALSE)) s_error("out of virtual memory"); }
int create_server(int port) { int sock; struct protoent *protocole; struct sockaddr_in adr_serv; protocole = getprotobyname("tcp"); if (protocole == 0) s_error("to get protocole"); sock = socket(PF_INET, SOCK_STREAM, protocole->p_proto); adr_serv.sin_family = AF_INET; adr_serv.sin_port = htons(port); adr_serv.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(sock, (const struct sockaddr *)&adr_serv, sizeof(adr_serv)) == -1) s_error("to bind the socket"); if (listen(sock, 10) == -1) s_error("to listen the socket"); return (sock); }
void EGLWindow::Initialize(const WindowConfig &config) { s_assert(!Available()); mConfig = config; mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); s_assert(Available()); s_assert(eglGetError() == EGL_SUCCESS); if (!eglInitialize(mEGLDisplay, nullptr, nullptr)) { s_error("Initialize EGL failed!\n"); return; } }
/** * Determine the file descriptor that will likely be used at next open(). * * This is used at initialization time to determine the first available * file descriptor so that we do not try to close special files opened by * libraries. * * @return the first available file descriptor. */ int fd_first_available(void) { int fd; fd = open("/dev/null", O_RDWR, 0); if (-1 == fd) s_error("%s(): failed to open /dev/null: %m", G_STRFUNC); close(fd); return fd; }
static void sock_handle_sendfile(int fd, void *data) { int error = 0; struct fstate_write *fs = data; assert(fs->out_fd == fd); int size_need = fs->size - fs->size_sent; int size_write = sendfile(fs->out_fd, fs->in_fd, (off_t *)&fs->offset, size_need); int res = 0; if(size_write == -1) { warning("sock_handle_sendfile fd %d %s\n", fd, strerror(errno)); if(ignore_error(errno)) { sock_set_event(fd, SOCK_EVENT_WR); sock_register_event(fd, NULL, NULL, sock_handle_sendfile, fs); } else { s_error("sock_handle_sendfile fd %d %s\n", fd, strerror(errno)); error = 1; WPF *handle = fs->callback; void *data = fs->data; res = fs->size_sent; safe_free(fs); handle(error, data, res); } return; } fs->size_sent += size_write; if(fs->size_sent < fs->size) { sock_set_event(fd, SOCK_EVENT_WR); sock_register_event(fd, NULL, NULL, sock_handle_sendfile, fs); } else { WPF *handle = fs->callback; res = fs->size_sent; void *data = fs->data; safe_free(fs); handle(error, data, res); } }
bool StorageFilesystem::Handle(const EventPtr event) { if (event->GetID() == IOEventType::RequestReadEventID) { auto readEvent = std::static_pointer_cast<IORequestReadEvent>(event); readEvent->SetData(GetStorage().Read(readEvent->GetLocation().GetPath())); } else if (event->GetID() == IOEventType::RequestWriteEventID) { auto writeEvent = std::static_pointer_cast<IORequestWriteEvent>(event); GetStorage().Write(writeEvent->GetLocation().GetPath(), writeEvent->GetData()); } else { s_error("storage filesystem: invalid event!\n"); } event->SetCompleted(); return true; }
void cache_index_init(void) { assert(config->cache_dir); if(config->cache_dir->count == 0) { s_error("cache_index_init dir count %d\n", config->cache_dir->count); abort(); } int i; char path[MAX_FILE]; for(i = 0; i < config->cache_dir->count; i++) { debug("cache_index_init begin scaning dir %d\n", i); struct cache_dir *dentry = config->cache_dir->items[i]; cache_index_read(dentry->index_fd); snprintf(path, MAX_FILE - 1, "%s/cache.index", dentry->path); unlink(path); } debug("cache_index_init Finish scan cache %d.\n", cache_num); }
/** * Compute special folder path. * * @param which_folder the special folder token * @param path sub-path underneath the special folder * * @return halloc()'ed full path, NULL if special folder is unknown. */ char * get_folder_path(enum special_folder which_folder, const char *path) { char *pathname; size_t offset = 0; const char *special_path = NULL; special_path = (*get_folder_basepath_func)(which_folder); if (NULL == special_path) return NULL; pathname = halloc(MAX_PATH_LEN); offset = clamp_strcpy(pathname, MAX_PATH_LEN, special_path); /* * A special folder MUST be an absolute path. */ if (!is_absolute_path(pathname)) { s_error("special folder %s is not an absolute path: %s", special_folder_name(which_folder), pathname); } /* * If we have a sub-path underneath the special folder, append it at the * tail of the path we already figured. */ if (path != NULL) { /* Add directory separator if missing at the tail of the special path */ if (offset > 0 && pathname[offset - 1] != G_DIR_SEPARATOR) pathname[offset++] = G_DIR_SEPARATOR; clamp_strcpy(&pathname[offset], MAX_PATH_LEN - offset, path); } return pathname; }
/** * Mark map as thread-safe. * * If the underlying implementation does not implement thread-safety, this * causes a fatal error. */ void map_thread_safe(const map_t *m) { const char *type = NULL; map_check(m); switch (m->type) { case MAP_HASH: htable_thread_safe(m->u.ht); return; case MAP_ORDERED_HASH: type = "ordered hash"; break; case MAP_PATRICIA: type = "PATRICIA"; break; case MAP_MAXTYPE: g_assert_not_reached(); } s_error("%s(): %s implementation is not thread-safe yet", G_STRFUNC, type); }
VOID s_break() { /* internal declarations */ i4 tok_type; /* next token type */ i4 rtn_char; /* ** dummy variable for s_g_skip() ** and real variable for ** s_g_ident(). */ char *name; /* break name */ bool err; char nrml_buf[(FE_MAXNAME + 1)]; /* start of routine */ if (St_b_given) { s_error(0x3A6, NONFATAL, NULL); s_cmd_skip(); return; } St_b_given = TRUE; save_em(); /* store aside the values of Command fields */ /* Initialize the fields in Command */ STcopy(NAM_BREAK, Ctype); STcopy(ERx(" "), Csection); STcopy(ERx(" "), Ccommand); if (Cact_ren == NULL) { s_error(0x38A, FATAL, NULL); } Csequence = Cact_ren->ren_bcount; err = FALSE; while (!err) { tok_type = s_g_skip(TRUE, &rtn_char); switch (tok_type) { case TK_ENDFILE: case TK_PERIOD: goto allexit; case TK_COMMA: break; case TK_ALPHA: case TK_QUOTE: case TK_DOLLAR: if (tok_type == TK_ALPHA) { name = s_g_ident(FALSE,&rtn_char, FALSE); if (rtn_char != UI_REG_ID) { s_error(0x39D,NONFATAL, name,NULL); s_cmd_skip(); err = TRUE; break; } IIUGdbo_dlmBEobject(name,FALSE); } else if (tok_type == TK_QUOTE) /* Delim ID */ { if (!St_xns_given) { s_error(0x39D,NONFATAL, name,NULL); s_cmd_skip(); err = TRUE; break; } name = s_g_ident(FALSE,&rtn_char, FALSE); if (rtn_char != UI_DELIM_ID) { s_error(0x39D,NONFATAL, name,NULL); s_cmd_skip(); err = TRUE; break; } _VOID_ IIUGdlm_ChkdlmBEobject(name, &nrml_buf[0], FALSE); name = &nrml_buf[0]; } else { name = s_g_name(FALSE); IIUGdbo_dlmBEobject(name,FALSE); } if (s_sbr_find(name) != NULL) { /* already specified */ s_error(0x39E, NONFATAL, name, NULL); s_cmd_skip(); err = TRUE; break; } /* name not specified. Add it */ s_sbr_add(name); STcopy(name,Cattid); _VOID_ s_w_row(); break; default: s_error(0x39D, NONFATAL, NULL); s_cmd_skip(); err = TRUE; break; } } allexit: get_em(); }
STATUS s_lrem_set() { char *b; char *bend; i4 pos; i4 n; i4 length; # ifdef UNIX char word[OOLONGREMSIZE+1]; # else char word[MAXCMD+1]; # endif i4 code; i4 count; char *save_Tokchar; char long_remark[OOLONGREMSIZE+1]; i4 rtn_char; /* dummy variable for sgskip */ if (St_lr_given) { s_error(0x3A9, NONFATAL, NULL); s_cmd_skip(); return FAIL; } if (Cact_ren == NULL) { s_error(0x38A, FATAL, NULL); } St_lr_given = TRUE; /* skip leading white space */ s_g_skip(TRUE, &rtn_char); /* handle rest of remark up to the .ENDREMARK */ code = S_ERROR; b = long_remark; bend = b + OOLONGREMSIZE; for (;;) { while (*Tokchar != '\n' && *Tokchar != EOS) { if (*Tokchar == '.' && CMalpha(Tokchar+1)) { /* check for .ENDREMARK */ save_Tokchar = Tokchar; Tokchar++; r_gt_word(word); CVlower(word); code = s_get_scode(word); if (code == S_ENDREMARK) { break; } else { Tokchar = save_Tokchar; } } if (b <= bend-CMbytecnt(Tokchar)) { if (*Tokchar == '\t') { /* if tab, replace it with the one blank */ *b = ' '; b++; Tokchar++; } else { CMcpyinc(Tokchar, b); } } else { CMnext(Tokchar); } } if (code == S_ENDREMARK) { *b = EOS; Cact_ren->ren_longrem = STalloc(long_remark); break; } else { if (b < bend) { *b++ = ' '; } count = s_next_line(); if (count == 0) { /* ERROR: EOF in middle of remark */ s_error(0x3A3, FATAL, NULL); break; } } } return OK; }
VOID s_out_set() { /* internal declarations */ char *name = NULL; /* hold name of table */ i4 rtn_char; /* dummy variable for sgskip */ /* start of routine */ if (Cact_ren == NULL) { s_error(906, FATAL, NULL); } if (St_o_given) { /* already specified */ s_error(922, NONFATAL, Cact_ren->ren_report, NULL); } save_em(); /* temp store of fields */ /* Set up fields in Command */ STcopy(NAM_OUTPUT,Ctype); Csequence = 0; STcopy(ERx(" "), Csection); STcopy(ERx(" "), Cattid); STcopy(ERx(" "), Ccommand); switch(s_g_skip(TRUE, &rtn_char)) { case(TK_ALPHA): case(TK_NUMBER): case(TK_DOLLAR): /* should be ok */ name = s_g_token(FALSE); break; case(TK_QUOTE): /* Keep the quotes #33314 */ name = s_g_string(FALSE, (i4) TK_QUOTE ); break; case(TK_SQUOTE): /* Keep the quotes #33314 */ name = s_g_string(FALSE, (i4) TK_SQUOTE ); break; default: s_error(912, NONFATAL, NULL); break; } if (name != NULL) { STcopy(name,Ctext); _VOID_ s_w_row(); } get_em(); St_o_given = TRUE; return; }