Skip to content

Commit be8efe8

Browse files
committed
build: Fix building for windows.
1 parent 489424e commit be8efe8

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ clib-build
1313
clib-update
1414
clib-upgrade
1515
clib-uninstall
16+
*.exe
1617

1718
test/package/package-*
1819
!test/package/package-*.c

deps/strdup/strdup.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#ifndef HAVE_STRDUP
1010

11+
#include "strdup.h"
1112
#include <stdlib.h>
1213
#include <string.h>
13-
#include "strdup.h"
1414

1515
#ifndef strdup
1616

@@ -30,6 +30,19 @@ strdup(const char *str) {
3030
return buf;
3131
}
3232

33+
char* strndup(const char *str, size_t len) {
34+
if (NULL == (char *) str) {
35+
return NULL;
36+
}
37+
38+
char *buf = malloc(len+1);
39+
40+
if (buf) {
41+
memset(buf, 0, len+1);
42+
memcpy(buf, str, len);
43+
}
44+
return buf;
45+
}
3346
#endif
3447

3548
#endif /* HAVE_STRDUP */

deps/strdup/strdup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
* Returns a pointer to the newly allocated
1818
* copy of `str`, or `NULL` on failure.
1919
*/
20-
20+
#include <stddef.h>
2121
#ifndef strdup
22-
char *
23-
strdup(const char *str);
22+
char * strdup(const char *str);
23+
char * strndup(const char *str, size_t len);
2424
#endif
2525

2626
#endif /* HAVE_STRDUP */

src/clib-search.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ int main(int argc, char *argv[]) {
182182
clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json");
183183

184184
clib_package_t *package = clib_package_load_local_manifest(0);
185-
registries_t registries = registry_manager_init_registries(package->registries, secrets);
185+
registries_t registries = registry_manager_init_registries(package ? package->registries : NULL, secrets);
186186
registry_manager_fetch_registries(registries);
187187

188188
// TODO, implement caching for the new registries.

src/common/clib-package-installer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include <limits.h>
2424
#include <strdup/strdup.h>
2525

26+
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \
27+
defined(__MINGW64__) || defined(__CYGWIN__)
28+
#define setenv(k, v, _) _putenv_s(k, v)
29+
#define realpath(a, b) _fullpath(a, b, strlen(a))
30+
#endif
31+
2632
CURLSH *clib_package_curl_share;
2733
//TODO, cleanup somewhere curl_share_cleanup(clib_package_curl_share);
2834

@@ -375,6 +381,7 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
375381
_debug("mkdir -p %s", pkg_dir);
376382
// create directory for pkg
377383
if (-1 == mkdirp(pkg_dir, 0777)) {
384+
logger_error("error", "Could not create directory %s", pkg_dir);
378385
rc = -1;
379386
goto cleanup;
380387
}

src/registry/gitlab-registry.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// MIT licensed
66
//
77
#include "gitlab-registry.h"
8-
#include "gumbo-get-element-by-id/get-element-by-id.h"
98
#include "http-get/http-get.h"
109
#include "registry-internal.h"
1110
#include <curl/curl.h>
1211
#include <string.h>
12+
#include <strdup/strdup.h>
1313

1414
/**
1515
* Parse a list of packages from the given `html`
@@ -19,9 +19,9 @@ static list_t *gitlab_registry_parse(const char *hostname, const char *html) {
1919

2020
// Try to parse the markdown file.
2121
char *input = strdup(html);
22-
char *line;
22+
char *line = input;
2323
char *category = NULL;
24-
while ((line = strsep(&input, "\n"))) {
24+
while ((line = strtok(line, "\n"))) {
2525
char *dash_position = strstr(line, "-");
2626
// The line starts with a dash, so we expect a package.
2727
if (dash_position != NULL && dash_position - line < 4) {

src/repository/repository.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static void *fetch_package_file_thread(void *arg) {
206206
int rc = fetch_package_file_work(data->url, data->dir, data->file, data->secret);
207207
*status = rc;
208208
pthread_exit((void *) status);
209+
return status;
209210
}
210211
#endif
211212

0 commit comments

Comments
 (0)