Code Monkey home page Code Monkey logo

Comments (5)

dannypsnl avatar dannypsnl commented on May 27, 2024

Please post source code next time, especially your C file is short.

I don't understand your environment, --dir=./Data will use Data/ as current directory from my understanding, and your code is trying to open a file named Data. Might you expand more?

In this sense, you will need to provide full steps including how you prepare your file system for the program.

from wasmedge.

Userzxcvbvnm avatar Userzxcvbvnm commented on May 27, 2024

Please post source code next time, especially your C file is short.

I don't understand your environment, --dir=./Data will use Data/ as current directory from my understanding, and your code is trying to open a file named Data. Might you expand more?

In this sense, you will need to provide full steps including how you prepare your file system for the program.

Thanks for your reply!
The c file is already uploaded a s test-c.txt, and the wasm file is already uploaded as test-wasm.txt, since .c and .wasm file cannot be uploaded. Please download the file and change the suffic.

from wasmedge.

dannypsnl avatar dannypsnl commented on May 27, 2024

No, I mean you can just post C code in code block.

from wasmedge.

Userzxcvbvnm avatar Userzxcvbvnm commented on May 27, 2024

No, I mean you can just post C code in code block.

Ok, here's the c code:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

int path_remove_directory(int basedir_fd, const char *file_name) {
    if (unlinkat(basedir_fd, file_name, AT_REMOVEDIR) == -1) {
        printf("Error deleting file.\n");
        close(basedir_fd);
        return 1;
    }

    printf("File deleted successfully.\n");
    return basedir_fd;
}

int get_fd(const char* file_name, int open_style){
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file.\n");
    }else{
        printf("Successfullly get the fle fd.\n");
    }

    return fd;
}

int main() {
    const char* file_name = "Data";
    int open_style= O_RDWR;
    int fd = get_fd(file_name, open_style);

    if (fd != -1){
        const char *file_name = "tmpdir";
        path_remove_directory(fd, file_name);
    }
    
    return 0;
}

from wasmedge.

yagehu avatar yagehu commented on May 27, 2024

This is not a bug with WasmEdge, you just need to change your O_RDWR to O_RDONLY. bytecodealliance/wasm-micro-runtime#2884

from wasmedge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.