splitting sources.
parent
298e1d13be
commit
0ee5425dfa
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* EXIF date tool
|
||||
*
|
||||
* (c) Alexander Vdolainen 2023 <alex@vapaa.xyz>
|
||||
*
|
||||
* this is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* this is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
|
||||
time_t exifdt_tm(const char *dtbuf)
|
||||
{
|
||||
struct tm tddt;
|
||||
char buf[5], *b = (char *)dtbuf;
|
||||
|
||||
if(!dtbuf) return (time_t) -1;
|
||||
if(strlen(dtbuf) < 18) return (time_t) -1;
|
||||
|
||||
memset(&tddt, 0, sizeof(struct tm));
|
||||
/* year */
|
||||
memset(buf, 0, 5);
|
||||
strncpy(buf, dtbuf, 4);
|
||||
tddt.tm_year = atoi(buf) - 1900;
|
||||
/* month */
|
||||
memset(buf, 0, 5);
|
||||
b = strchr(b, ':');
|
||||
if(!b) return (time_t) -1;
|
||||
else b++;
|
||||
strncpy(buf, b, 2);
|
||||
tddt.tm_mon = atoi(buf) - 1;
|
||||
/* day */
|
||||
memset(buf, 0, 5);
|
||||
b = strchr(b, ':');
|
||||
if(!b) return (time_t) -1;
|
||||
else b++;
|
||||
strncpy(buf, b, 2);
|
||||
tddt.tm_mday = atoi(buf);
|
||||
/* hour */
|
||||
memset(buf, 0, 5);
|
||||
b = strchr(b, ' ');
|
||||
if(!b) return (time_t) -1;
|
||||
else b++;
|
||||
strncpy(buf, b, 2);
|
||||
tddt.tm_hour = atoi(buf);
|
||||
/* minute */
|
||||
memset(buf, 0, 5);
|
||||
b = strchr(b, ':');
|
||||
if(!b) return (time_t) -1;
|
||||
else b++;
|
||||
strncpy(buf, b, 2);
|
||||
tddt.tm_min = atoi(buf);
|
||||
/* second */
|
||||
memset(buf, 0, 5);
|
||||
b = strchr(b, ':');
|
||||
if(!b) return (time_t) -1;
|
||||
else b++;
|
||||
strncpy(buf, b, 2);
|
||||
tddt.tm_sec = atoi(buf);
|
||||
|
||||
return mktime(&tddt);
|
||||
}
|
Loading…
Reference in New Issue