// ***************************************************************************************************************** void beispiele(void){ char datei[12]="TEST TXT"; // hier muss platz für 11 zeichen sein (8.3), da fat_str diesen string benutzt !! fat_str(datei); // wandelt "test.txt" in das fat format 8.3 der form: "TEST TXT" muss immer dieses Format haben, auch ordner !! // 0.) ______________löschen von dateien/ordnern (ordner rekursiv)____________________________________________ ffrm( datei ); // löschen der datei/ordner falls vorhanden // 1.) ______________anlegen und schreiben____________________________________________________________________ // öffnet datei, wenn nicht vorhanden, legt ffopen datei an (rückgabewert = 1 datei existiert, also nur öffnen, 2 = angelegt). ffopen( datei ); // schreibt string ffwrites((char*)"Hallo Datei :)"); // neue zeile in der datei ffwrite(0x0D); ffwrite(0x0A); // schließt datei ffclose(); // 2.)________________ändern von vorhandenen daten in dateien__________________________________________________ ffopen( datei ); // siehe oben... ffseek(12); // spult in datei auf position 12 vor (fängt immer bei 0 an zu zählen !) ffwrite(';'); // schreibt dann ab position 12 (überschreibt daten der datei, hier nur 1 zeichen) ffclose(); // schließt datei // 3.)________________lesen von dateien_________________________________________________________________________ ffopen( datei ); // siehe oben... unsigned long int seek=file.length; // eine variable setzen und runterzählen bis 0 geht am schnellsten ! do{ uputc(ffread()); // liest ein zeichen und gibt es über uart aus ! }while(--seek); // liest solange bytes da sind (von datei länge bis 0) ffclose(); // schließt datei uputc('\n'); // neue zeile weil neue unteraufgabe // 4.)________________anhängen von daten an datei_______________________________________________________________ ffopen( datei); // siehe oben... ffseek(file.length); // spult in datei ans ende ffwrites((char*)"Dies ist ein Test..."); // siehe oben // neue zeile in der datei ffwrite(0x0D); ffwrite(0x0A); ffclose(); // schließt datei // 3.)________________lesen von dateien_________________________________________________________________________ ffopen( datei ); // siehe oben... seek=file.length; // eine variable setzen und runterzählen bis 0 geht am schnellsten ! do{ uputc(ffread()); // liest ein zeichen und gibt es über uart aus ! }while(--seek); // liest solange bytes da sind (von datei länge bis 0) ffclose(); // schließt datei }
static create_macro(char *path, Boolean realtime) { Errcode err; close_macro(); /* will re-initialize everything to zeros */ if((err = ffopen(path,&Mcb.fp,"wb+")) < Success) goto error; Mcb.mh.id.type = MAC_MAGIC; if((err = ffwrite(Mcb.fp,&Mcb.mh,sizeof(Mcb.mh))) < Success) goto error; icb.macro_clocked = Mcb.mh.realtime = realtime; icb.macro_mode = MAKE_MACRO; /* these values should force recording of data the first time */ Mcb.lastmouse.x = Mcb.lastmouse.y = -30000; /* values highly unlikely */ Mcb.last_histate = ~0U; /* value that won't exist */ Mcb.last_pressure = ~0; /* valure that won't exist */ return(Success); error: close_macro(); pj_delete(macro_name); return(softerr(err,"!%s", "macro_create", path )); }
/* * Sortof like ftruncate, except won't make the * file shorter. */ static int fgrow(const int fd, const off_t len) { struct ffc_stat_s sb; struct ffsw sw; if (fffcntl(fd, FC_STAT, &sb, &sw) < 0) return errno; if (len < sb.st_size) return ENOERR; { const long dumb = 0; /* cache current position */ const off_t pos = ffseek(fd, 0, SEEK_CUR); if(pos < 0) return errno; if (ffseek(fd, len-sizeof(dumb), SEEK_SET) < 0) return errno; if(ffwrite(fd, (void *)&dumb, sizeof(dumb)) < 0) return errno; if (ffseek(fd, pos, SEEK_SET) < 0) return errno; } /* else */ return ENOERR; }
static int ffio_pgout(ncio *const nciop, off_t const offset, const size_t extent, const void *const vp, off_t *posp) { #ifdef X_ALIGN assert(offset % X_ALIGN == 0); assert(extent % X_ALIGN == 0); #endif if(*posp != offset) { if(ffseek(nciop->fd, offset, SEEK_SET) != offset) { return errno; } *posp = offset; } if(ffwrite(nciop->fd, vp, extent) != extent) { return errno; } *posp += extent; return ENOERR; }
/* * Sortof like ftruncate, except won't make the file shorter. Differs * from fgrow by only writing one byte at designated seek position, if * needed. */ static int fgrow2(const int fd, const off_t len) { struct ffc_stat_s sb; struct ffsw sw; if (fffcntl(fd, FC_STAT, &sb, &sw) < 0) return errno; if (len <= sb.st_size) return ENOERR; { const char dumb = 0; /* we don't use ftruncate() due to problem with FAT32 file systems */ /* cache current position */ const off_t pos = ffseek(fd, 0, SEEK_CUR); if(pos < 0) return errno; if (ffseek(fd, len-1, SEEK_SET) < 0) return errno; if(ffwrite(fd, (void *)&dumb, sizeof(dumb)) < 0) return errno; if (ffseek(fd, pos, SEEK_SET) < 0) return errno; } return ENOERR; }
static Errcode rgb_scale_x(Rgbctl *ctl, Rcel *screen) /***************************************************************************** * Read rgb file, break it into RGB components, scale the components * in the X dimension, and write them out to our RGB files. ****************************************************************************/ { Errcode err = Success; int height = ctl->height; int width = ctl->width; int dwidth = screen->width; UBYTE *scale_buf = NULL; Cmap *cmap = screen->cmap; int j; int i; int sofar = 0; soft_status_line("ctop_xscale"); if (NULL == (scale_buf = pj_malloc(dwidth))) { err = Err_no_memory; goto OUT; } if (Success > (err = open_rgb_files("wb",3))) goto OUT; if (Success > (err = pdr_rgb_seekstart(ctl->ifile))) goto OUT; for (i=0; i<height; ++i) { if (--sofar <= 0) { if ((err = soft_abort("rgb_abort")) < Success) goto OUT; soft_status_line("!%d%d", "ctop_scaleline", i, height); sofar = 25; } if ((err = pdr_rgb_readline(ctl->ifile, ctl->linebuf)) < Success) goto OUT; rgb3_to_buffers(ctl->linebuf, ctl->rgb_bufs, width); j = 3; while (--j >= 0) { pix_ave_scale(ctl->rgb_bufs[j], width, scale_buf, dwidth); if ((err = ffwrite(rgb_files[j], scale_buf, dwidth)) < Success) goto OUT; } } OUT: pj_gentle_free(scale_buf); close_rgb_files(); return err; }
size_t stdiof_ffwrite(const void *buf, size_t recsz, size_t numrec, FILE *stream) { int fd; size_t reqdbytes; size_t repval; size_t recdone; fd = (long)stream; /* redfine it to be what it actually is */ reqdbytes = recsz * numrec; repval = ffwrite(fd, (void *)buf, reqdbytes); recdone = repval / recsz; return ( recdone ); }
static Errcode write_abort_rec() { Errcode err; UBYTE buf[32]; /* for now only 7 levels possible */ void *abuf; Abortnest *pan; buf[0] = MACRO_REC|MR_POLLABORT; abuf = &buf[1]; if(Mcb.ar.flags & AR_ABORTLEVEL) /* we are aborting from here */ { pan = &abort; while(pan != NULL) { VPUTVAL(abuf,SHORT,pan->count); buf[0] += ABORTLEVEL_1; pan = (void *)(pan->pop); } } if((err = ffwrite(Mcb.fp,&buf,SIZE(buf,abuf))) < Success) return(macro_write_error(err)); return(Success); }
void close_macro(void) { BYTE olevel; static UBYTE eoflags[2] = {(MACRO_REC|MR_EOF),(MACRO_REC|MR_EOF)}; if(Mcb.fp != NULL) { if(icb.macro_mode == MAKE_MACRO) { Mcb.mh.id.size = fftell(Mcb.fp); ffwrite(Mcb.fp,&eoflags,sizeof(eoflags)); /* two bytes of eof */ ffwriteoset(Mcb.fp,&Mcb.mh,0,sizeof(Mcb.mh)); } ffclose(&Mcb.fp); } /* clear all but abort nesting level count */ olevel = Mcb.ab_level; clear_struct(&Mcb); Mcb.ab_level = olevel; icb.macro_clocked = 0; icb.macro_mode = 0; }
int myconfig_change() { char *conffile = g_runtime->conffile; char conffile_tmp[PATH_MAX]; DINFO("change config file...\n"); snprintf(conffile_tmp, PATH_MAX, "%s.tmp", conffile); FILE *fp = fopen64(conffile_tmp, "wb"); char line[512] = {0}; snprintf(line, 512, "block_data_count = %d,%d,%d,%d\n", g_cf->block_data_count[0], g_cf->block_data_count[1], g_cf->block_data_count[2], g_cf->block_data_count[3]); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "block_data_reduce = %0.1f\n", g_cf->block_data_reduce); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "dump_interval = %d\n", g_cf->dump_interval); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "block_clean_cond = %0.1f\n", g_cf->block_clean_cond); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "block_clean_start = %d\n", g_cf->block_clean_start); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "block_clean_num = %d\n", g_cf->block_clean_num); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "read_port = %d\n", g_cf->read_port); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "write_port = %d\n", g_cf->write_port); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "sync_port = %d\n", g_cf->sync_port); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "data_dir = %s\n", g_cf->datadir); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "log_level = %d\n", g_cf->log_level); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "log_name = %s\n", g_cf->log_name); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "timeout = %d\n", g_cf->timeout); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "thread_num = %d\n", g_cf->thread_num); ffwrite(line, strlen(line), 1, fp); if (g_cf->write_binlog == 1) snprintf(line, 512, "write_binlog = %s\n", "yes"); else snprintf(line, 512, "write_binlog = %s\n", "no"); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "max_conn = %d\n", g_cf->max_conn); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "max_read_conn = %d\n", g_cf->max_read_conn); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "max_write_conn = %d\n", g_cf->max_write_conn); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "max_core = %d\n", g_cf->max_core); ffwrite(line, strlen(line), 1, fp); if (g_cf->is_daemon == 1) snprintf(line, 512, "is_daemon = %s\n", "yes"); else snprintf(line, 512, "is_daemon = %s\n", "no"); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "%s\n", "# master/backup/slave"); ffwrite(line, strlen(line), 1, fp); if (g_cf->role == ROLE_MASTER) snprintf(line, 512, "role = %s\n", "master"); else if (g_cf->role == ROLE_BACKUP) snprintf(line, 512, "role = %s\n", "backup"); else if (g_cf->role == ROLE_SLAVE) snprintf(line, 512, "role = %s\n", "slave"); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "master_sync_host = %s\n", g_cf->master_sync_host); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "master_sync_port = %d\n", g_cf->master_sync_port); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "sync_check_interval = %d\n", g_cf->sync_check_interval); ffwrite(line, strlen(line), 1, fp); snprintf(line, 512, "user = %s\n", g_cf->user); ffwrite(line, strlen(line), 1, fp); int ret; ret = rename(conffile_tmp, conffile); if (ret < 0) { char errbuf[1024]; strerror_r(errno, errbuf, 1024); DERROR("conffile rename error %s\n", errbuf); } fclose(fp); return 1; }
// ******************************************************************************************************************************* // schreibt string auf karte, siehe ffwrite() // ******************************************************************************************************************************* inline void ffwrites(const char *s ){ while (*s) ffwrite(*s++); }
Errcode put_macro(Boolean ishit) { Errcode err; char buf[36]; USHORT *oflags; void *macbuf; #define Flags (*((USHORT *)buf)) if(!ishit) /* just checking increment check count */ { ++Mcb.iocount; return(Success); } macbuf = buf; VPUTVAL(macbuf,USHORT,icb.state & MACSTATE); if(Mcb.iocount > 0) { oflags = macbuf; *oflags = icb.ostate & MACSTATE; macbuf = OPTR(macbuf,sizeof(USHORT)); if(Mcb.iocount <= 0x0FF) { VPUTVAL(macbuf,UBYTE,Mcb.iocount); } else if(Mcb.iocount <= 0x0FFFF) { VPUTVAL(macbuf,USHORT,Mcb.iocount); *oflags |= CCOUNT_SHORT; } else { VPUTVAL(macbuf,ULONG,Mcb.iocount); *oflags |= CCOUNT_LONG; } if(icb.lastsx != Mcb.lastmouse.x) { VPUTVAL(macbuf,SHORT,icb.lastsx); *oflags |= HAS_MOUSEX; } if(icb.lastsy != Mcb.lastmouse.y) { VPUTVAL(macbuf,SHORT,icb.lastsy); *oflags |= HAS_MOUSEY; } if(HISTATE_BITS(icb.ostate) != Mcb.last_histate) { VPUTVAL(macbuf,USHORT,HISTATE_BITS(icb.ostate)); *oflags |= HAS_HISTATE; } Flags |= HAS_CCOUNT; } Mcb.iocount = 0; if(Flags & KEYHIT) { VPUTVAL(macbuf,USHORT,icb.inkey); } if(icb.pressure != Mcb.last_pressure) { VPUTVAL(macbuf,UBYTE,icb.pressure); Mcb.last_pressure = icb.pressure; Flags |= HAS_PRESSURE; } if(icb.sx != Mcb.lastmouse.x) { VPUTVAL(macbuf,SHORT,icb.sx); Flags |= HAS_MOUSEX; } if(icb.sy != Mcb.lastmouse.y) { VPUTVAL(macbuf,SHORT,icb.sy); Flags |= HAS_MOUSEY; } Mcb.lastmouse = *((Short_xy *)&icb.sx); if(HISTATE_BITS(icb.state) != Mcb.last_histate) { Mcb.last_histate = HISTATE_BITS(icb.state); VPUTVAL(macbuf,USHORT,Mcb.last_histate); Flags |= HAS_HISTATE; } if((err = ffwrite(Mcb.fp,buf,SIZE(buf,macbuf))) < Success) macro_write_error(err); return(err); #undef Flags }