Mercurial > pidgin
comparison src/util.c @ 9716:8158d148b3c2
[gaim-migrate @ 10577]
Changed the use of localtime_r to localtime in util.c
Also changed some spaces to tabs
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 08 Aug 2004 14:06:58 +0000 |
parents | a57fa78e5752 |
children | 25866d09063d |
comparison
equal
deleted
inserted
replaced
9715:b030f83693da | 9716:8158d148b3c2 |
---|---|
19 * You should have received a copy of the GNU General Public License | 19 * You should have received a copy of the GNU General Public License |
20 * along with this program; if not, write to the Free Software | 20 * along with this program; if not, write to the Free Software |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 */ | 22 */ |
23 #include "internal.h" | 23 #include "internal.h" |
24 | |
25 #include <errno.h> | |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
28 | 24 |
29 #include "conversation.h" | 25 #include "conversation.h" |
30 #include "debug.h" | 26 #include "debug.h" |
31 #include "prpl.h" | 27 #include "prpl.h" |
32 #include "prefs.h" | 28 #include "prefs.h" |
506 } | 502 } |
507 | 503 |
508 time_t | 504 time_t |
509 gaim_str_to_time(const char *timestamp, gboolean utc) | 505 gaim_str_to_time(const char *timestamp, gboolean utc) |
510 { | 506 { |
511 struct tm t; | 507 struct tm *t; |
512 time_t retval = 0; | 508 time_t retval = 0; |
513 char buf[32]; | 509 char buf[32]; |
514 char *c; | 510 char *c; |
515 int tzoff = 0; | 511 int tzoff = 0; |
516 | 512 |
517 time(&retval); | 513 time(&retval); |
518 localtime_r(&retval, &t); | 514 t = localtime(&retval); |
519 | 515 |
520 snprintf(buf, sizeof(buf), "%s", timestamp); | 516 snprintf(buf, sizeof(buf), "%s", timestamp); |
521 c = buf; | 517 c = buf; |
522 | 518 |
523 /* 4 digit year */ | 519 /* 4 digit year */ |
524 if(!sscanf(c, "%04d", &t.tm_year)) return 0; | 520 if (!sscanf(c, "%04d", &t->tm_year)) return 0; |
525 c+=4; | 521 c += 4; |
526 if(*c == '-') | 522 if (*c == '-') |
527 c++; | 523 c++; |
528 | 524 |
529 t.tm_year -= 1900; | 525 t->tm_year -= 1900; |
530 | 526 |
531 /* 2 digit month */ | 527 /* 2 digit month */ |
532 if(!sscanf(c, "%02d", &t.tm_mon)) return 0; | 528 if (!sscanf(c, "%02d", &t->tm_mon)) return 0; |
533 c+=2; | 529 c += 2; |
534 if(*c == '-') | 530 if (*c == '-') |
535 c++; | 531 c++; |
536 | 532 |
537 t.tm_mon -= 1; | 533 t->tm_mon -= 1; |
538 | 534 |
539 | 535 /* 2 digit day */ |
540 /* 2 digit day */ | 536 if (!sscanf(c, "%02d", &t->tm_mday)) return 0; |
541 if(!sscanf(c, "%02d", &t.tm_mday)) return 0; | 537 c += 2; |
542 c+=2; | 538 if (*c == 'T' || *c == '.') { /* we have more than a date, keep going */ |
543 if(*c == 'T' || *c == '.') { /* we have more than a date, keep going */ | 539 c++; /* skip the "T" */ |
544 c++; /* skip the "T" */ | 540 |
545 | 541 /* 2 digit hour */ |
546 /* 2 digit hour */ | 542 if (sscanf(c, "%02d:%02d:%02d", &t->tm_hour, &t->tm_min, &t->tm_sec) == 3 || |
547 if(sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 || | 543 sscanf(c, "%02d%02d%02d", &t->tm_hour, &t->tm_min, &t->tm_sec) == 3) { |
548 sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) { | 544 int tzhrs, tzmins; |
549 int tzhrs, tzmins; | 545 c += 8; |
550 c+=8; | 546 if (*c == '.') /* dealing with precision we don't care about */ |
551 if(*c == '.') /* dealing with precision we don't care about */ | 547 c += 4; |
552 c += 4; | 548 if ((*c == '+' || *c == '-') && |
553 | 549 sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) { |
554 if((*c == '+' || *c == '-') && | 550 tzoff = tzhrs*60*60 + tzmins*60; |
555 sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) { | 551 if (*c == '+') |
556 tzoff = tzhrs*60*60 + tzmins*60; | 552 tzoff *= -1; |
557 if(*c == '+') | 553 } |
558 tzoff *= -1; | 554 |
559 } | 555 if (tzoff || utc) { |
560 | |
561 if(tzoff || utc) { | |
562 | |
563 #ifdef HAVE_TM_GMTOFF | 556 #ifdef HAVE_TM_GMTOFF |
564 tzoff += t.tm_gmtoff; | 557 tzoff += t->tm_gmtoff; |
565 #else | 558 #else |
566 # ifdef HAVE_TIMEZONE | 559 # ifdef HAVE_TIMEZONE |
567 tzset(); /* making sure */ | 560 tzset(); /* making sure */ |
568 tzoff -= timezone; | 561 tzoff -= timezone; |
569 # endif | 562 # endif |
570 #endif | 563 #endif |
571 } | 564 } |
572 } | 565 } |
573 } | 566 } |
574 | 567 |
575 t.tm_isdst = -1; | 568 t->tm_isdst = -1; |
576 | 569 retval = mktime(t); |
577 retval = mktime(&t); | 570 retval += tzoff; |
578 | 571 |
579 retval += tzoff; | 572 return retval; |
580 | 573 } |
581 return retval; | |
582 } | |
583 | |
584 | 574 |
585 | 575 |
586 /************************************************************************** | 576 /************************************************************************** |
587 * Markup Functions | 577 * Markup Functions |
588 **************************************************************************/ | 578 **************************************************************************/ |
1917 dir[len++] = G_DIR_SEPARATOR; | 1907 dir[len++] = G_DIR_SEPARATOR; |
1918 | 1908 |
1919 if(g_file_test(dir, G_FILE_TEST_IS_DIR)) { | 1909 if(g_file_test(dir, G_FILE_TEST_IS_DIR)) { |
1920 continue; | 1910 continue; |
1921 } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) { | 1911 } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) { |
1922 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "bad path: %s\n", path); | 1912 gaim_debug_warning("build_dir", "bad path: %s\n", path); |
1923 g_strfreev(components); | 1913 g_strfreev(components); |
1924 g_free(dir); | 1914 g_free(dir); |
1925 return -1; | 1915 return -1; |
1926 } | 1916 } |
1927 | 1917 |
1928 if (mkdir(dir, mode) < 0) { | 1918 if (mkdir(dir, mode) < 0) { |
1929 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "mkdir: %s\n", strerror(errno)); | 1919 gaim_debug_warning("build_dir", "mkdir: %s\n", strerror(errno)); |
1930 g_strfreev(components); | 1920 g_strfreev(components); |
1931 g_free(dir); | 1921 g_free(dir); |
1932 return -1; | 1922 return -1; |
1933 } | 1923 } |
1934 } | 1924 } |