Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Add custom strcasestr and use custom gnu type functions in bflsc
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolivas committed Sep 7, 2014
1 parent 14a9e42 commit 25304f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 1 addition & 3 deletions driver-bflsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include "uthash.h"
#include "driver-bflsc.h"

#include "util.h"

int opt_bflsc_overheat = BFLSC_TEMP_OVERHEAT;

static const char *blank = "";
Expand Down Expand Up @@ -633,7 +631,7 @@ static bool getinfo(struct cgpu_info *bflsc, int dev)
sc_dev.firmware = strdup(fields[0]);
sc_info->driver_version = drv_ver(bflsc, sc_dev.firmware);
}
else if (strstr(firstname, BFLSC_DI_ENGINES)) {
else if (Strcasestr(firstname, BFLSC_DI_ENGINES)) {
sc_dev.engines = atoi(fields[0]);
if (sc_dev.engines < 1) {
tmp = str_text(items[i]);
Expand Down
29 changes: 27 additions & 2 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,30 @@ static void __maybe_unused timersubspec(struct timespec *a, const struct timespe
spec_nscheck(a);
}

#ifdef WIN32
/* Mingw32 has no strsep so create our own custom one */
char *Strcasestr(char *haystack, const char *needle)
{
char *lowhay, *lowneedle, *ret;
int hlen, nlen, i, ofs;

if (unlikely(!haystack || !needle))
return NULL;
hlen = strlen(haystack);
nlen = strlen(needle);
if (!hlen || !nlen)
return NULL;
lowhay = alloca(hlen);
lowneedle = alloca(nlen);
for (i = 0; i < hlen; i++)
lowhay[i] = tolower(haystack[i]);
for (i = 0; i < nlen; i++)
lowneedle[i] = tolower(needle[i]);
ret = strstr(lowhay, lowneedle);
if (!ret)
return ret;
ofs = ret - lowhay;
return haystack + ofs;
}

char *Strsep(char **stringp, const char *delim)
{
char *ret = *stringp;
Expand All @@ -1163,6 +1185,9 @@ char *Strsep(char **stringp, const char *delim)
return ret;
}

#ifdef WIN32
/* Mingw32 has no strsep so create our own custom one */

/* Windows start time is since 1601 LOL so convert it to unix epoch 1970. */
#define EPOCHFILETIME (116444736000000000LL)

Expand Down
4 changes: 2 additions & 2 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
{
return (errno == EINTR);
}
#define Strsep(a, b) strsep(a, b)
#elif defined WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
Expand Down Expand Up @@ -63,7 +62,6 @@
#ifndef in_addr_t
#define in_addr_t uint32_t
#endif
char *Strsep(char **stringp, const char *delim);
#endif

#define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
Expand Down Expand Up @@ -122,6 +120,8 @@ void us_to_timeval(struct timeval *val, int64_t us);
void us_to_timespec(struct timespec *spec, int64_t us);
void ms_to_timespec(struct timespec *spec, int64_t ms);
void timeraddspec(struct timespec *a, const struct timespec *b);
char *Strcasestr(char *haystack, const char *needle);
char *Strsep(char **stringp, const char *delim);
void cgsleep_ms(int ms);
void cgsleep_us(int64_t us);
void cgtimer_time(cgtimer_t *ts_start);
Expand Down

0 comments on commit 25304f0

Please sign in to comment.