diff --git a/nasmlib.c b/nasmlib.c
index fd388128..20535c8a 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -156,6 +156,25 @@ int nasm_strnicmp(const char *s1, const char *s2, int n)
 }
 #endif
 
+#if !defined(strsep)
+char *nasm_strsep(char **stringp, const char *delim)
+{
+        char *s = *stringp;
+        char *e;
+
+        if (!s)
+                return NULL;
+
+        e = strpbrk(s, delim);
+        if (e)
+                *e++ = '\0';
+
+        *stringp = e;
+        return s;
+}
+#endif
+
+
 #define lib_isnumchar(c)   ( isalnum(c) || (c) == '$')
 #define numvalue(c)  ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
 
@@ -755,7 +774,7 @@ int stdscan(void *private_data, struct tokenval *tv)
     if (isidstart(*stdscan_bufptr) ||
         (*stdscan_bufptr == '$' && isidstart(stdscan_bufptr[1]))) {
         /* now we've got an identifier */
-        int i;
+        uint32_t i;
         int is_sym = FALSE;
 
         if (*stdscan_bufptr == '$') {
diff --git a/nasmlib.h b/nasmlib.h
index 22e229d7..4bfec686 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -71,6 +71,13 @@ int nasm_stricmp(const char *, const char *);
 int nasm_strnicmp(const char *, const char *, int);
 #endif
 
+#if defined(strsep)
+#define nasm_strsep strsep
+#else
+char *nasm_strsep(char **stringp, const char *delim);
+#endif
+
+
 /*
  * Convert a string into a number, using NASM number rules. Sets
  * `*error' to TRUE if an error occurs, and FALSE otherwise.
diff --git a/output/outmacho.c b/output/outmacho.c
index 6f18cf0d..7efdc713 100644
--- a/output/outmacho.c
+++ b/output/outmacho.c
@@ -537,7 +537,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
         sectionAttributes = NULL;
     } else {
         sectionAttributes = name;
-        name = strtok((char*)&sectionAttributes, " \t");
+        name = nasm_strsep(&sectionAttributes, " \t");
     }
 
     for (sm = sectmap; sm->nasmsect != NULL; ++sm) {
@@ -572,7 +572,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
             }
 
             while ((NULL != sectionAttributes)
-                   && (currentAttribute = strtok((char*)&sectionAttributes, " \t"))) {
+                   && (currentAttribute = nasm_strsep(&sectionAttributes, " \t"))) {
                 if (0 != *currentAttribute) {
                     if (!nasm_strnicmp("align=", currentAttribute, 6)) {
                         char *end;
@@ -1037,7 +1037,7 @@ static void macho_write_symtab (void)
     struct symbol *sym;
     struct section *s;
     int32_t fi;
-    int32_t i;
+    uint32_t i;
 
     /* we don't need to pad here since MACHO_RELINFO_SIZE == 8 */
 
@@ -1102,7 +1102,7 @@ static void macho_write_symtab (void)
 static void macho_fixup_relocs (struct reloc *r)
 {
     struct symbol *sym;
-    int i;
+    uint32_t i;
 
     while (r != NULL) {
 	if (r->ext) {