LINUX.ORG.RU

История изменений

Исправление invy, (текущая версия) :

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

int main()
{
    unsigned int allocSize = 256;
    char *cwd = malloc(allocSize);
    while(getcwd(cwd, allocSize) == NULL)
    {
        int err = errno;
        if(err != ERANGE)
        {
            return err;
        }
        allocSize = (float)allocSize * 1.5f;
        cwd = realloc(cwd, allocSize);
        if(cwd == NULL)
        {
            return -1;
        }
    }
    fprintf(stdout, "Current working dir: %s, size = %d\n", cwd, allocSize);
    return 0;
}

Исправление invy, :

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

int main()
{
    unsigned int allocSize = 256;
    char *cwd = malloc(allocSize);
    while(getcwd(cwd, allocSize) == NULL)
    {
        int err = errno;
        if(err != ERANGE)
        {
            return err;
        }
        allocSize = (float)allocSize * 1.5f;
        cwd = realloc(cwd, allocSize);
        if(cwd == NULL)
            return -1;
    }
    fprintf(stdout, "Current working dir: %s, size = %d\n", cwd, allocSize);
    return 0;
}

Исправление invy, :

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

int main()
{
    unsigned int allocSize = 256;
    char *cwd = malloc(allocSize);
    while(getcwd(cwd, allocSize) == NULL)
    {
        int err = errno;
        if(err != ERANGE)
        {
            free(cwd);
            return err;
        }
        allocSize = (float)allocSize * 1.5f;
        cwd = realloc(cwd, allocSize);
        if(cwd == NULL)
            return -1;
    }
    fprintf(stdout, "Current working dir: %s, size = %d\n", cwd, allocSize);
    return 0;
}

Исходная версия invy, :

#include <unistd.h> #include <stdio.h> #include <errno.h> #include <stdlib.h>

int main()
{
    unsigned int allocSize = 256;
    char *cwd = malloc(allocSize);
    while(getcwd(cwd, allocSize) == NULL)
    {
        int err = errno;
        if(err != ERANGE)
        {
            free(cwd);
            return err;
        }
        allocSize = (float)allocSize * 1.5f;
        cwd = realloc(cwd, allocSize);
        if(cwd == NULL)
            return -1;
    }
    fprintf(stdout, "Current working dir: %s, size = %d\n", cwd, allocSize);
    return 0;
}