// opens a filename either in truncate ('>') or append ('>>') mode // and returns its file descriptor int get_outfile(PARSED *tokens) { REDIRECTION file = _get_filename(*tokens, ">>"); if (file.file_name != NULL) { int fd = open(file.file_name, O_WRONLY | O_APPEND | O_CREAT, 0770); if (fd == -1) { f_error(">>", file.file_name); exit(EXIT_FAILURE); } free(file.file_name); *tokens = file.tokens; return fd; } else { file = _get_filename(*tokens, ">"); if (file.file_name != NULL) { int fd = open(file.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0770); if (fd == -1) { f_error(">>", file.file_name); exit(EXIT_FAILURE); } free(file.file_name); *tokens = file.tokens; return fd; } } return -1; }
DEFALIAS(editmem, e) { int i; u_char *addr; char buffer[64]; if( argc < 2 ){ f_error("edit addr"); return -1; } addr = (char*)atoi_base(16, argv[1] ); /* hit return to skip to next byte a number to change the value . when done (this is exactly the 'q' command on your Sun3) */ for( ; ; addr++){ printf("%08.8X : %02.2x > ", addr, *addr); getline(buffer, 64, 0); if(! *buffer) continue; if(*buffer== '.') break; if(*buffer =='?') puts("enter a value, return to skip, or . when done\n"); *addr = atoi_base(16, buffer); } return 0; }
static void to_time(char * r_file) { if (opts.reference == 1) { /* get timestamp from reference file */ struct stat buf; if (stat(r_file, &buf) == -1) { f_error(r_file, "couldn't stat"); exit(EXIT_FAILURE); } #if defined (__linux__) times[0].tv_sec = buf.st_atim.tv_sec; times[0].tv_nsec = buf.st_atim.tv_nsec; times[1].tv_sec = buf.st_mtim.tv_sec; times[1].tv_nsec = buf.st_mtim.tv_nsec; #else times[0].tv_sec = buf.st_atim.tv_sec; times[0].tv_usec = buf.st_atim.tv_nsec; times[1].tv_sec = buf.st_mtim.tv_sec; times[1].tv_usec = buf.st_mtim.tv_nsec; #endif } else if (opts.date == 1) { // parse time } else if (opts.time == 1) { //parse date } }
void OnGetFileError(nwazetMessageContext_t* nmc){ fileObjectMap_t* fileObj = GetFileObjectById(nmc); if(fileObj){ uint8_t error = f_error(fileObj->file); StartResponse(nmc, FR_OK, false); Put(nmc->respContext, (void*)&error, sizeof(error), 1); EndResponse(nmc); } }
GameState *loadGame(char *filename){ FILE *in = fopen(filename, 'r'); if (in == NULL){ f_error(filename); exit(0); } GameState *state = (GameState*)malloc(sizeof(GameState)); if (state == NULL){ exit(2); } }
// opens a filename and returns its file descriptor int get_infile(PARSED *tokens) { REDIRECTION file = _get_filename(*tokens, "<"); if (file.file_name != NULL) { int fd = open(file.file_name, O_RDONLY); if (fd == -1) { f_error("<", file.file_name); exit(EXIT_FAILURE); } free(file.file_name); *tokens = file.tokens; return fd; } return -1; }
DEFALIAS(dumpmem, d) { int len, i; u_char *addr; int col = 0; char txt[BPL + 1]; if( argc < 2 ){ f_error("dump addr [len]"); return -1; } addr = (char*)atoi_base(16, argv[1] ); if( argc > 2 ) len = atoi_base(16, argv[2] ); else len = 16; txt[BPL] = 0; for(i=0; i<len; i++){ if( !col ) printf("%08.8X: ", addr + i); if(! (col % IGO )) printf(" "); printf("%02.2x", addr[i]); txt[col] = (isprint(addr[i])) ? addr[i] : '.'; if( ++col == BPL){ printf(" %s\n", txt); col = 0; } } if( col ){ /* do partial last line */ txt[col] = 0; for(; col<BPL; col++){ printf(" "); if(! (col % IGO)) printf(" "); } printf(" %s\n", txt); } return 0; }
SDFS_status_type SDFS_readString(FIL* fp, char* text, uint32_t len) { SDFS_status_type ret_wert = SDFS_RD_STRING_ERR; int check; f_gets(text, len, fp); check = f_eof(fp); if (check != 0) return (SDFS_EOF); check = f_error(fp); if (check != 0) return (SDFS_RD_STRING_ERR); ret_wert = SDFS_OK; return (ret_wert); }
DEFALIAS(show, sh) { char buf[32]; short i; if( argc != 2 ){ f_error("show what?"); return -1; } i = interp_var(env, argv[1], buf, sizeof(buf)); if( !i ){ printf("%s = %s\n", argv[1], buf); #ifdef USE_FILESYS }else if( !strcmp(argv[1], "run") ){ // show run ui_f_config(0, 0, env); #endif }else{ f_error("show: no such var"); return -1; } return 0; }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ SystemClock_Config(); uint8_t lcd_status = LCD_OK; HAL_MspInit(); HAL_Init(); BSP_SDRAM_Init(); // uint32_t i; int i; __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_InitStructure.Pull = GPIO_NOPULL; //GPIO_PULLDOWN;//GPIO_PULLUP;// GUI_Conf.border=8; GPIO_InitStructure.Pin = GPIO_PIN_6; HAL_GPIO_Init(GPIOG,&GPIO_InitStructure); GPIO_InitStructure.Pin = GPIO_PIN_5; HAL_GPIO_Init(GPIOD,&GPIO_InitStructure); GPIO_InitStructure.Pin = GPIO_PIN_4; HAL_GPIO_Init(GPIOD,&GPIO_InitStructure); GPIO_InitStructure.Pin = GPIO_PIN_3; HAL_GPIO_Init(GPIOK,&GPIO_InitStructure); BSP_LCD_Reset(); BSP_LCD_MspInit(); //lcd_status = BSP_LCD_InitEx(LCD_ORIENTATION_PORTRAIT); //lcd_status = BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE); lcd_status = BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_SelectLayer(0); BSP_LCD_DisplayOn(); BSP_LCD_SetTransparency(0,0xff); if(lcd_status!=LCD_OK) f_error(); BSP_LCD_Clear(LCD_COLOR_BLACK); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0,BSP_LCD_GetXSize(),BSP_LCD_GetYSize()); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillRect(GUI_Conf.border, GUI_Conf.border,BSP_LCD_GetXSize()-2*GUI_Conf.border,BSP_LCD_GetYSize()-2*GUI_Conf.border); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_SetFont(&Font16); BSP_LCD_SetBackColor(LCD_COLOR_TRANSPARENT); BSP_LCD_DisplayStringAtLine(1, (uint8_t *)" FAT SD"); while(1){ Delay(1000); switch(i%4){ case 0: HAL_GPIO_TogglePin(GPIOG,GPIO_PIN_6); break; case 1: HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_4); break; case 2: HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_5); break; case 3: HAL_GPIO_TogglePin(GPIOK,GPIO_PIN_3); break; } i++; if(! i%4) i=0; } }
uint8_t FatFs::File::error() { return f_error(&file); }
DEFALIAS(dir, ll) { int how=0, i; const char *what; MountEntry *me; if( !strcmp(argv[0], "ll") ) how = LSHOW_ALL | LSHOW_LONG ; if( !strcmp(argv[0], "ls") ) how = LSHOW_SHORT ; if( argc == 1) what = ""; else{ if( argv[1][0] == '-' ){ for(i=how=0; argv[1][i]; i++){ switch( argv[1][i] ){ case 'a': how |= LSHOW_ALL; break; case 'd': how |= LSHOW_DEVS; break; case 'f': how |= LSHOW_FSYS; break; case 'x': how |= LSHOW_EXT; break; case 'l': how |= LSHOW_LONG; break; case 's': how |= LSHOW_SHORT; break; case 'h': printf("-a\tall\n-d\tdevs\n-f\tfilesys\n-l\tlong\n-s\tshort\n"); return 0; } } what = argc>2 ? argv[2] : ""; }else{ what = argc>1 ? argv[1] : ""; if( !strcmp(argv[1], DEVPREFIX) ){ how |= LSHOW_DEVS; what = ""; } if( !strcmp(argv[1], ":") ){ how |= LSHOW_FSYS; what = ""; } if( !strcmp(argv[1], "::") ){ how |= LSHOW_DEVS | LSHOW_FSYS | LSHOW_LONG; what = ""; } } } if( (how & LSHOW_FSYS) || (how & LSHOW_DEVS) ){ if( how & LSHOW_FSYS ){ // synthesize a "dev" filesystem printf("\tdev:%s\n", (how & LSHOW_LONG) ? "\ttype dev" : ""); } /* list all devs or filesystems */ me = mountlist; while( me ){ if( (me->flags & MNTE_F_DEV) && (how & LSHOW_DEVS) || (me->flags & MNTE_F_FS) && (how & LSHOW_FSYS) ){ printf("\t%s", me->name); if( how & LSHOW_LONG ){ if( me->fscf && me->fscf->name ) printf("\ttype %s", me->fscf->name); } printf("\n"); } me = me->next; } return 0; } #ifdef USE_FILESYS me = find_mount(what); if( me ) what = basenameoffile(what); #ifdef USE_PROC if( !me ) me = currproc->cwd; #endif if( !me ){ fsmsg("no such file or device\n"); return -1; } if( me->fscf && me->fscf->ops ) i = (me->fscf->ops)(FSOP_DIR, me, how, what); else i = -1; if( i ) f_error("ls [-adfxl] [me]"); return i; #else f_error("no filesys configured\n"); return -1; #endif }
bool File::is_ready() { return f_error(&f) == 0; }