All pastes #367 Raw Edit

storage function

public c v1 · immutable
#367 ·published 2004-07-30 04:52 UTC
rendered paste body
/* Storage Functions */int store_browser(unsigned int id, unsigned short year, unsigned char month, char *browser) {  BROWSER *b;  pthread_mutex_lock(&browsers_mutex);  /* First see if we find an existing entry */  b = browsers;  while(b) {    if(THIS_MONTH(b) && strcmp(b->browser, browser) == 0) {      break;    }    b = b->next;  }  /* pointer will be NULL if no current entry was found */  /* create a new one if needed                         */  if(!b) {    b = (BROWSER *)malloc(sizeof(BROWSER));    if(!b) return 1;    memset(b, 0, sizeof(BROWSER));    b->id       = id;    b->year     = year;    b->month    = month;    memcpy(b->browser, browser, pstrlen(browser));    b->next     = browsers;    browsers    = b;  }  /* Update the entry information */  b->hits++;  /* NOW LEAVE! */  pthread_mutex_unlock(&browsers_mutex);  return 0;}