comparison src/util.c @ 13095:5a7c4570d768

[gaim-migrate @ 15457] Add some g_return_val_if_fail() guards to our local implementations of g_str_has_prefix() and g_str_has_suffix(). Glib has these, and it may help prevent crashes. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 02 Feb 2006 18:42:28 +0000
parents b553326bc468
children f1bf8989bbf2
comparison
equal deleted inserted replaced
13094:8c87818c98a1 13095:5a7c4570d768
2482 gaim_str_has_prefix(const char *s, const char *p) 2482 gaim_str_has_prefix(const char *s, const char *p)
2483 { 2483 {
2484 #if GLIB_CHECK_VERSION(2,2,0) 2484 #if GLIB_CHECK_VERSION(2,2,0)
2485 return g_str_has_prefix(s, p); 2485 return g_str_has_prefix(s, p);
2486 #else 2486 #else
2487 if (!strncmp(s, p, strlen(p))) 2487 g_return_val_if_fail(s != NULL, FALSE);
2488 return TRUE; 2488 g_return_val_if_fail(p != NULL, FALSE);
2489 2489
2490 return FALSE; 2490 return (!strncmp(s, p, strlen(p)));
2491 #endif 2491 #endif
2492 } 2492 }
2493 2493
2494 gboolean 2494 gboolean
2495 gaim_str_has_suffix(const char *s, const char *x) 2495 gaim_str_has_suffix(const char *s, const char *x)
2496 { 2496 {
2497 #if GLIB_CHECK_VERSION(2,2,0) 2497 #if GLIB_CHECK_VERSION(2,2,0)
2498 return g_str_has_suffix(s, x); 2498 return g_str_has_suffix(s, x);
2499 #else 2499 #else
2500 int off = strlen(s) - strlen(x); 2500 int off;
2501 2501
2502 if (off >= 0 && !strcmp(s + off, x)) 2502 g_return_val_if_fail(s != NULL, FALSE);
2503 return TRUE; 2503 g_return_val_if_fail(x != NULL, FALSE);
2504 2504
2505 return FALSE; 2505 off = strlen(s) - strlen(x);
2506 return (off >= 0 && !strcmp(s + off, x));
2506 #endif 2507 #endif
2507 } 2508 }
2508 2509
2509 char * 2510 char *
2510 gaim_str_add_cr(const char *text) 2511 gaim_str_add_cr(const char *text)