/* ** brief: it will display a specific message for our file and exit ** @file: our file like test[.s] ** @msg: our message */ void my_error(const char *file, const char *msg) { my_write(2, "File ", my_strlen("File ")); my_write(2, file, my_strlen(file)); my_write(2, msg, my_strlen(msg)); exit(EXIT_FAILURE); }
int write_fs(){ my_write(sb_object,sizeof(sb),0); my_write(db_bmap_object,sizeof(db_bmap),sb_object->data_block_bmap_offset); my_write(inode_bmap_object,sizeof(*inode_bmap_object),sb_object->inode_bmap_offset); my_write(inode_table_object,sizeof(*inode_table_object),sb_object->inode_table_offset); return 0; }
/* ** Will use our global variable */ char my_print_error(int i) { if (i > 133 || i < 0) return (my_write(g_fd, "Unknown error ", 14) + my_putnbr(i)); my_write(g_fd, g_my_tab[i], my_strlen(g_my_tab[i])); return (0); }
t_info *alloc_t_info(char *file) { t_info *all; all = xmalloc(sizeof (t_info)); all->name = NULL; all->comment = NULL; if ((all->fd_input = open(file, O_RDONLY, 0666)) == -1) { my_write(STDOUT_FILENO, file, my_strlen(file)); my_write(STDOUT_FILENO, ERR_FILE, my_strlen(ERR_FILE)); return (NULL); } all->inputfile = file; all->fd_output = 0; all->size_prog = 0; all->pos_buf = 0; all->size_buf = 0; all->line = 0; all->do_encode = 1; all->tete_words = NULL; all->tete_label = NULL; all->tete_cmd = NULL; return (all); }
void put_in_stdout(char *com, int fd[2], int type) { char *buf; char **tab; int file; tab = get_command(com); my_close(fd[1]); if (type == 3) file = open(tab[0], O_WRONLY | O_APPEND | O_CREAT, 0644); else file = open(tab[0], O_WRONLY | O_CREAT | O_TRUNC, 0644); if (file == -1) { my_putstr("Error open file\n"); return; } while ((buf = get_next_line(fd[0]))) { my_write(file, buf, my_strlen(buf)); my_write(file, "\n", 1); free(buf); } free_tab(tab); my_close(file); }
void retr(t_server *serv, char *cmd) { int fd; char buf[1]; int nb; if (serv->data->pasv == 0) my_write(serv->client_fd, "425 Use PORT or PASV first\r\n"); else { if (strcmp(cmd, "RETR") == 0) { my_write(serv->client_fd, "550 fail\r\n"); xclose(serv->data->client_fd); } else if ((fd = my_open(serv, cmd)) != -1) { my_write(serv->client_fd, "150 file status OK\r\n"); while ((nb = read(fd, buf, 1)) > 0) write(serv->data->client_fd, buf, 1); xclose(serv->data->client_fd); my_write(serv->client_fd, "226 Transfert completed\r\n"); } } serv->data->pasv = 0; }
void put_in_stdin(char *com, int fd, t_com *elem) { char **tab; char *tmp; int file; tab = get_command(com); tmp = my_strdup(elem->com); free(elem->com); elem->com = my_strdup(elem->prev->prev->com); free(elem->prev->prev->com); elem->prev->prev->com = my_strdup(tmp); free(tmp); file = open(tab[0], O_RDONLY, 0644); if (file == -1) my_putstr("Error open file\n"); if (file == -1) elem->prev = NULL; if (file == -1) return; while ((tmp = get_next_line(file))) { my_write(fd, tmp, my_strlen(tmp)); my_write(fd, "\n", 1); free(tmp); } free_tab(tab); }
void prend(t_plyr *player, char *param) { char *(objs[7]); int i; t_map *node; i = 0; objs[0] = strdup("nourriture"); objs[1] = strdup("linemate"); objs[2] = strdup("deraumère"); objs[3] = strdup("sibur"); objs[4] = strdup("mendiane"); objs[5] = strdup("phiras"); objs[6] = strdup("thystame"); while (strncmp(param, objs[i], strlen(objs[i])) != 0 && i < 7) ++i; node = get_map(&map, player->x, player->y); if (rm_obj(&(node->objects), (e_id)i) == 1) my_write(player->so, "ko", 2); else { if (i == 0) player->live += 126; else push_obj(&(player->objs_perso), (e_id)i); my_write(player->so, "ok", 2); } }
long int sock_write(net_sock_t *nsock, tbuffer_t *buf, size_t bpos, size_t len, Net_timeout_t tm) { int err, ewait; // eno; apr_size_t nbytes; // Net_timeout_t end_time; network_sock_t *sock = (network_sock_t *)nsock; //if (sock == NULL) log_printf(15, "sock_write: sock == NULL\n"); if (sock == NULL) return(-1); //** If closed return if (sock->fd == NULL) return(-1); // end_time = apr_time_now() + tm; err = my_write(sock, buf, bpos, len, &nbytes); if (err != APR_SUCCESS) { ewait = sock_io_wait(sock, tm, SOCK_WAIT_WRITE); my_write(sock, buf, bpos, len, &nbytes); if ((ewait == 1) && (nbytes < 1)) nbytes = -1; } //eno = errno; //if (nbytes == -1) log_printf(4, "sock_write: count=" ST " nbytes=%ld err=%d errno=%d\n", count, nbytes, err, eno); //log_printf(15, "sock_write: count=" ST " nbytes=%ld\n", count, nbytes); return(nbytes); }
/* ** brief: if there is any error this function will print a message and exit ** @error: it will display this message ** @str: our file/line where there is a problem */ void my_puterror_file(char *error, char *str) { my_write(2, error, my_strlen(error)); my_write(2, " ", 1); my_write(2, str, my_strlen(str)); my_write(2, "\n", 1); exit(EXIT_FAILURE); }
static int run_query(const char *query, DYNAMIC_STRING *ds_res, my_bool force) { int ret; File fd; char query_file_path[FN_REFLEN]; const uchar sql_log_bin[]= "SET SQL_LOG_BIN=0;"; DBUG_ENTER("run_query"); DBUG_PRINT("enter", ("query: %s", query)); if ((fd= create_temp_file(query_file_path, opt_tmpdir[0] ? opt_tmpdir : NULL, "sql", O_CREAT | O_SHARE | O_RDWR, MYF(MY_WME))) < 0) die("Failed to create temporary file for defaults"); /* Master and slave should be upgraded separately. All statements executed by mysql_upgrade will not be binlogged. 'SET SQL_LOG_BIN=0' is executed before any other statements. */ if (!opt_write_binlog) { if (my_write(fd, sql_log_bin, sizeof(sql_log_bin)-1, MYF(MY_FNABP | MY_WME))) { my_close(fd, MYF(0)); my_delete(query_file_path, MYF(0)); die("Failed to write to '%s'", query_file_path); } } if (my_write(fd, (uchar*) query, strlen(query), MYF(MY_FNABP | MY_WME))) { my_close(fd, MYF(0)); my_delete(query_file_path, MYF(0)); die("Failed to write to '%s'", query_file_path); } ret= run_tool(mysql_path, ds_res, "--no-defaults", ds_args.str, "--database=mysql", "--batch", /* Turns off pager etc. */ force ? "--force": "--skip-force", ds_res || opt_silent ? "--silent": "", "<", query_file_path, "2>&1", NULL); my_close(fd, MYF(0)); my_delete(query_file_path, MYF(0)); DBUG_RETURN(ret); }
void print_stats(int tid, char *cmd) { FILE *file, *login_file; char path[50], line[50], user_id[USERID_LENGTH], buf[10]; char msg[MSG_LENGTH]; char *str = msg; sscanf(cmd, "%s %s", buf, user_id); if ( (login_file = fopen("./login/login_details.dat", "r")) == NULL) { my_error("Unable to open login file"); } else { char id[USERID_LENGTH]; char passwd[PASSWORD_LENGTH]; bool is_registered = false; while (fscanf(login_file, "%s %s[^\n]", id, passwd) != EOF) { if (strcmp(id, user_id) == 0) { is_registered = true; break; } } fclose(login_file); if (is_registered == false) { my_write(client[tid].cli_sock, "User does not exist.", 20); return; } } sprintf(path, "./gameplay/%s_stat.dat", user_id); if ( (file = fopen(path, "a+")) == NULL) { my_error("Cannont open user stat file"); } else { while (fgets(line, 50, file) != NULL) { str += sprintf(str, "%s", line); } bool is_online = false; for (int i = 0; i < CLIENT_SIZE; ++i) { // Check if user is online if (client[i].cli_sock != -1) { if (strcmp(user_id, client[i].user_id) == 0) { is_online = true; break; } } } if (is_online == true) str += sprintf(str, "\n%s is currently online", user_id); else str += sprintf(str, "\n%s is currently offline", user_id); my_write(client[tid].cli_sock, msg, strlen(msg)); fclose(file); } }
void cwd(t_server *serv, char *cmd) { int ret; ret = 0; if ((ret = chdir(cmd)) == -1) my_write(serv->client_fd, "501 Error\r\n"); else my_write(serv->client_fd, "250 Requested file action okay, completed.\r\n"); }
int _nisam_write_static_record(N_INFO *info, const byte *record) { uchar temp[4]; /* Not sizeof(long) */ if (info->s->state.dellink != NI_POS_ERROR) { ulong filepos=info->s->state.dellink; info->rec_cache.seek_not_done=1; /* We have done a seek */ VOID(my_seek(info->dfile,info->s->state.dellink+1,MY_SEEK_SET,MYF(0))); if (my_read(info->dfile,(char*) &temp[0],sizeof(temp), MYF(MY_NABP))) goto err; info->s->state.dellink=uint4korr(temp); if (info->s->state.dellink == (uint32) ~0) /* Fix for 64 bit long */ info->s->state.dellink=NI_POS_ERROR; info->s->state.del--; info->s->state.empty-=info->s->base.reclength; VOID(my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0))); if (my_write(info->dfile, (char*) record, info->s->base.reclength, MYF(MY_NABP))) goto err; } else { if (info->s->state.data_file_length > info->s->base.max_data_file_length) { my_errno=HA_ERR_RECORD_FILE_FULL; return(2); } if (info->opt_flag & WRITE_CACHE_USED) { /* Cash in use */ if (my_b_write(&info->rec_cache, (byte*) record, info->s->base.reclength)) goto err; } else { info->rec_cache.seek_not_done=1; /* We have done a seek */ VOID(my_seek(info->dfile,info->s->state.data_file_length, MY_SEEK_SET,MYF(0))); if (my_write(info->dfile,(char*) record,info->s->base.reclength, MYF(MY_NABP | MY_WAIT_IF_FULL))) goto err; } info->s->state.data_file_length+=info->s->base.reclength; info->s->state.splitt++; } return 0; err: return 1; }
main() { int i, j; my_init(MEMORY_SIZE, PHYSICAL_MEM_LIMIT); /* The MEMORY SIZE is in megabytes */ /* PHYSICAL MEMORY SIZE is in number of system pages */ /* The page size on Sparc 4 and Sparc 5 is 4Kb */ dump_out(); for (i = 0; i < NUM_BUFS; i++) { sbuf[i] = (char *)my_malloc(SMALL_BUF_SIZE); lbuf[i] = (char *)my_malloc(LARGE_BUF_SIZE); printf("The buffer small pointers is %x and large pointer is %x.\n",(unsigned)sbuf[i],(unsigned)lbuf[i] ); dump_out(); } for (i = 0; i < NUM_BUFS; i++) { memset(temp_buffer, 'A'+i, LARGE_BUF_SIZE); my_write(sbuf[i], SMALL_BUF_SIZE, temp_buffer); my_write(lbuf[i], LARGE_BUF_SIZE, temp_buffer); my_read(lbuf[i], LARGE_BUF_SIZE, temp_buffer); } read_start(); my_read(lbuf[NUM_BUFS-1], LARGE_BUF_SIZE, temp_buffer); my_write(lbuf[0], LARGE_BUF_SIZE, temp_buffer); my_read(lbuf[NUM_BUFS - 1], LARGE_BUF_SIZE, temp_buffer); my_write(lbuf[1]+5, 3, temp_buffer); my_read(sbuf[NUM_BUFS-1], SMALL_BUF_SIZE, temp_buffer); my_write(sbuf[0], SMALL_BUF_SIZE, temp_buffer); my_read(sbuf[NUM_BUFS - 1], SMALL_BUF_SIZE, temp_buffer); my_write(sbuf[1]+5, 3, temp_buffer); read_start(); for (i = 0; i < NUM_BUFS; i++) { memset(temp_buffer, 'Z'-i, LARGE_BUF_SIZE); my_write(sbuf[i] + 5, SMALL_BUF_SIZE - 5, temp_buffer); my_read(sbuf[i], SMALL_BUF_SIZE, temp_buffer); my_write(lbuf[i] + 5, LARGE_BUF_SIZE - 5, temp_buffer); } read_start(); for (i = 0; i < NUM_BUFS; i++) { my_free((void *) sbuf[i]); my_free((void *) lbuf[i]); } dump_out(); my_terminate(); }
/* considered a failure. */ int atomic_log_send() { char *buf; list *current; int len; if (fd < 0) { errno = EINVAL; return -1; } len = get_length(); if (len == 0) return 0; buf = (char *)malloc(len); if (buf == NULL) return -1; current = first; len = 0; while (current != NULL) { (void)memcpy(buf+len, current->entry, current->len); len += current->len; current = current->next; } if (my_write(fd, buf, len) != len) { free(buf); errno = EAGAIN; return -1; } free(buf); clear(); return 0; }
int toto() { char toto[] = "Coucou Ca Va ?"; char test[20]; char dest[7]; printf("sa marche ? toto fait %d char\n", my_strlen("toto")); my_memcpy(dest, toto, 14); dest[14] = 0; printf("dest = [%s]\n", dest); printf("strchr = [%s]\n", my_strchr(toto, 'a')); printf("strcmp toto, dest = %d\n", my_strcmp(toto + 1, dest)); dest[3] = 'a'; printf("strncmp toto, dest = %d\n", my_strncmp(toto, dest, 3)); my_bzero(toto, 5); printf("bzero = [%s]\n", toto + 5); printf("strcasecmp = %d\n", strcasecmp("SALUT", "123456")); my_write(1, "test\n", 5); printf("rindex my toto with the char 'a' : [%s]\n", my_rindex("caca coco coucou", 'i')); test[14] = 0; printf("apres le memset = [%s]\n", my_memset(test, 'A', 14)); strcpy(dest, "Coucou"); printf("memmove result = [%s]\n", memmove(dest, dest + 1, 20)); printf("dest = [%s]\n", dest); }
void quit(t_server *serv, char *cmd) { (void)cmd; serv->connect = 0; my_write(serv->client_fd, "221 Logout.\r\n"); xclose(serv->fd); }
static void *async_write(void *argv) { struct logger *l = &logger; pthread_detach(pthread_self()); while (1) { mysleep_millisec(l->write_interval); if (l->nerror == 1) { close(l->fd); l->fd = -1; if (log_open_file(l->name) < 0) { printf("open log file failed\n"); continue; } } int wpos = 0; int index = l->buffer_index; l->buffer_index = (l->buffer_index + 1) % 2; pthread_mutex_lock(&l->buffer_locks[index]); wpos = l->buffer_wpos[index]; if (wpos > 0 && my_write(l->fd, l->buffer[index], wpos) < 0) { l->nerror = 1; } l->buffer_wpos[index] = 0; pthread_mutex_unlock(&l->buffer_locks[index]); } }
int _nisam_update_static_record(N_INFO *info, ulong pos, const byte *record) { info->rec_cache.seek_not_done=1; /* We have done a seek */ VOID(my_seek(info->dfile,pos,MY_SEEK_SET,MYF(0))); return (my_write(info->dfile,(char*) record,info->s->base.reclength, MYF(MY_NABP)) != 0); }
static void recvfrom_alarm(int signo) { printf("时间到!\n"); //+ // printf("pipefd[1] = %d\n", pipefd[1]); //+ my_write(pipefd[1], "", 1); return ; }
main() { int file_desc, i, j; char buffer[100]; for(i=0; i<100; i++) buffer[i] = ' '; j = 1; while(j == 1) { file_desc = open("a:\dummy", O_CREAT | O_RDWR | O_BINARY, S_IREAD | S_IWRITE); printf("\nCAT> file desc=%d", file_desc); for(i=0; i<10; i++) { my_write(file_desc, buffer, 100); } printf("\n\tfinished writing"); close(file_desc); } }
int logger_vprintf(LOGGER_HANDLE *log, const char* fmt, va_list ap) { int result; my_off_t filesize; char cvtbuf[1024]; size_t n_bytes; mysql_mutex_lock(&log->lock); if (log->rotations > 0) if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 || ((unsigned long long)filesize >= log->size_limit && do_rotate(log))) { result= -1; errno= my_errno; goto exit; /* Log rotation needed but failed */ } n_bytes= my_vsnprintf(cvtbuf, sizeof(cvtbuf), fmt, ap); if (n_bytes >= sizeof(cvtbuf)) n_bytes= sizeof(cvtbuf) - 1; result= my_write(log->file, (uchar *) cvtbuf, n_bytes, MYF(0)); exit: mysql_mutex_unlock(&log->lock); return result; }
static int _log_internal(char *str_buf, int len) { struct logger *l = &logger; int index = 0; int wpos = 0; if (NULL == str_buf || len == 0) { return 0; } index = l->buffer_index; pthread_mutex_lock(&l->buffer_locks[index]); wpos = l->buffer_wpos[index]; if (wpos + len < l->max_buffer_size) { strncpy(l->buffer[index] + wpos, str_buf, len); l->buffer_wpos[index] += len; } else { if (wpos > 0 && my_write(l->fd, l->buffer[index], wpos) < 0) { l->nerror = 1; } l->buffer_wpos[index] = 0; strncpy(l->buffer[index], str_buf, len); l->buffer_wpos[index] += len; } pthread_mutex_unlock(&l->buffer_locks[index]); return 0; }
ssize_t df_write(int fd, void *buf, size_t count) { size_t written_so_far = 0; ssize_t written_this_time = 0; while (written_so_far < count) { if (dbg) { fprintf(stderr, WRITE_FMT, fd, buf + written_so_far, buf, written_so_far, count - written_so_far, count, written_this_time); } written_this_time = my_write(fd, buf + written_so_far, count - written_so_far); if (-1 == written_this_time) return -errno; if (0 == written_this_time) return 0; written_so_far += written_this_time; } assert(written_so_far == count); return written_so_far; }
byte DiskWrite(byte ID,byte *Buf,int N) { if((ID<MAXDRIVES)&&(Drives[ID]>=0)&&!RdOnly[ID]) if(my_lseek(ID,N*512L,0)==N*512L) return(my_write(ID,Buf,512)==512); return(0); }
int myrg_create(const char *name, const char **table_names, uint insert_method, my_bool fix_names) { int save_errno; uint errpos; File file; char buff[FN_REFLEN],*end; DBUG_ENTER("myrg_create"); errpos=0; if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT,4),0, O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) goto err; errpos=1; if (table_names) { for ( ; *table_names ; table_names++) { strmov(buff,*table_names); if (fix_names) fn_same(buff,name,4); *(end=strend(buff))='\n'; end[1]=0; if (my_write(file,buff,(uint) (end-buff+1), MYF(MY_WME | MY_NABP))) goto err; } } if (insert_method != MERGE_INSERT_DISABLED) { end=strxmov(buff,"#INSERT_METHOD=", get_type(&merge_insert_method,insert_method-1),"\n",NullS); if (my_write(file,buff,(uint) (end-buff),MYF(MY_WME | MY_NABP))) goto err; } if (my_close(file,MYF(0))) goto err; DBUG_RETURN(0); err: save_errno=my_errno ? my_errno : -1; switch (errpos) { case 1: VOID(my_close(file,MYF(0))); } DBUG_RETURN(my_errno=save_errno); } /* myrg_create */
unsigned BatchSpawn( const char *cmd ) { buff[0] = LNK_RUN; strcpy( &buff[1], cmd ); my_write( pipeHdl, buff, strlen( buff ) ); return( 0 ); }
unsigned BatchChdir( const char *new_dir ) { buff[0] = LNK_CWD; strcpy( &buff[1], new_dir ); my_write( pipeHdl, buff, strlen( buff ) + 1 ); my_read( pipeHdl, buff, sizeof( buff ) ); return( *(unsigned long *)&buff[1] ); }
void BatchUnlink( int shutdown ) { char done; done = shutdown ? LNK_SHUTDOWN : LNK_DONE; my_write( pipeHdl, &done, sizeof( done ) ); _dos_close( pipeHdl ); }