ScrapExplorer - touch.c

Home / usr / light_builtins Lines: 4 | Size: 1220 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* Light builtins's (C Version) 2 * touch - create a new file or update the timestamp of an existing file 3 * A lightweight repository of useful shell commands 4 * GitHub: https://www.github.com/0x4248/light_builtins 5 * Licence: GNU General Public License v3.0 6 * By: 0x4248 7 */ 8 9#include "config.h" 10#include <stdio.h> 11#include <stdlib.h> 12#include <string.h> 13#include <time.h> 14 15int main(int argc, char *argv[]) { 16 if (argc >= 2 && 17 (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { 18 printf("Light Builtins (C) %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, 19 VERSION_PATCH, EXTRA_VERSION); 20 return 0; 21 } 22 23 if (argc != 2) { 24 fprintf(stderr, "Usage: touch [Filename]\n"); 25 return 1; 26 } 27 28 FILE *fp = fopen(argv[1], "w"); 29 if (fp == NULL) { 30 fprintf(stderr, "Touch: error creating file\n"); 31 return 1; 32 } 33 34 time_t now; 35 time(&now); 36 37 fprintf(fp, " "); 38 39 fseek(fp, -1, SEEK_CUR); 40 fputc(fgetc(fp), fp); 41 42 struct tm *timeinfo; 43 timeinfo = localtime(&now); 44 char time_str[80]; 45 strftime(time_str, 80, "%c", timeinfo); 46 47 fclose(fp); 48 49 return 0; 50} 51
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.