windows memory formatting issue for quality standards, yes quality standards : I am trying to make this dynamic reallocation work in a potable fashion.  I have this code which works clean on linux but when I run it on windows it emits garbage.  Does anyone know why/how to make this portable only using malloc.  IE not using string.h(strcpy) str... anything but len.  If you don't understand why please don't answer this question.  If you code in csharp, get a life, and please don't answer. c17 only - no broken stucts(not portable). here is my code. Compiles with no errors gcc 7.3, mingw 7.3.  I replace gets and puts with safer functions  and I still get garbage on windows.  I assume this is a formatting issue...

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <malloc.h>

    void
    wbuff
    (message)
     char *message;
    {
    FILE *f = fopen("file.txt", "w");
    fprintf(f, "%s", message);
    fclose(f);
    }

    char
    *rean
      (message)
     char *message;
    {
    /* performs (write) on buffer, trims lefover, then restores */

    char buf[80] = "";
    puts("enter a line");
    gets(buf);

    int bln  =  strlen( buf );
    int mln  =  strlen( message );
    int nln  =  bln + mln;
    printf("new length %d\n", nln);

    message = realloc(message, nln);
    memmove(message + mln, buf, bln);

    /* MISTAKE IS HERE?! */
    if( nln >= 20 ) {

     int exl  = nln -20;                        // leftover length
     char *lo = realloc(NULL, exl);             // leftover placeholder
     memmove(lo, message+20, exl);              // copy leftover
     wbuff(message);                            // write clear buff
     message = realloc(NULL, nln);
     message = realloc(NULL, exl);              // resize buffer
     memmove(message, lo, exl);                 // restore leftover
    }

    return message;
    }

    void
    main
    (void)
    {
    char *message = "";
    message = realloc(NULL, 0);
    while ( 1 == 1 ) {
     message = rean( message );
     puts(message);
    }
    return;
    }




