IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage C++ Discussion :

Problème à l'appel de la fonction mkdir.


Sujet :

Langage C++

  1. #1
    Invité
    Invité(e)
    Par défaut Problème à l'appel de la fonction mkdir.
    Salut! J'utilise un éditeur pour générer des scripts en c++ et des fichiers seulement j'ai un problème à la création du nouveau dossier du projet :
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    void ODFAEGCreator::actionPerformed(Button* button) {
        if (button->getText() == "Create") {
            appliname = ta->getText();
            std::ofstream applis("applis");
            applis<<appliname<<std::endl;
            applis.close();
            applitype = dpList->getSelectedItem();
            path = fdTexturePath->getAppiDir() + "/" + appliname;
            const char* lcars = appliname.c_str();
            char* ucars = new char[appliname.size()];
            for (unsigned int i = 0; i < appliname.length(); i++) {
                ucars[i] = std::toupper(lcars[i]);
            }
            std::string majAppliname (ucars, appliname.length());
            delete ucars;
            ucars = new char[appliname.size()];
            for (unsigned int i = 0; i < appliname.length(); i++) {
                ucars[i] = std::tolower(lcars[i]);
            }
            minAppliname = std::string(ucars, appliname.length());
            if(!mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
                std::cerr<<"Failed to create application directory!";
            wApplicationNew->setVisible(false);
            if (applitype == "Normal") {
                std::ofstream header(path+"/"+minAppliname+".hpp");
                std::cerr << "Error: " << strerror(errno);
                header<<"#ifndef "<<majAppliname<<"_HPP"<<std::endl;
                header<<"#define "<<majAppliname<<"_HPP"<<std::endl;
                header<<"#include \"/usr/local/include/odfaeg/Core/application.h\""<<std::endl;
                header<<"class "<<appliname<<" : public odfaeg::core::Application {"<<std::endl;
                header<<"   public : "<<std::endl;
                header<<"   "<<appliname<<"(sf::VideoMode vm, std::string title);"<<std::endl;
                header<<"   void onLoad();"<<std::endl;
                header<<"   void onInit();"<<std::endl;
                header<<"   void onRender(odfaeg::graphic::RenderComponentManager* cm);"<<std::endl;
                header<<"   void onDisplay(odfaeg::graphic::RenderWindow* window);"<<std::endl;
                header<<"   void onUpdate (odfaeg::graphic::RenderWindow*, sf::Event& event);"<<std::endl;
                header<<"   void onExec ();"<<std::endl;
                header<<"};"<<std::endl;
                header<<"#endif"<<std::endl;
                header.close();
                std::ofstream source(path+"/"+minAppliname+".cpp");
                source<<"#include \""+path+"/"+minAppliname+".hpp\""<<std::endl;
                source<<"using namespace odfaeg::graphic;"<<std::endl;
                source<<appliname<<"::"<<appliname<<"(sf::VideoMode vm, std::string title) : "<<std::endl;
                source<<"Application (vm, title, sf::Style::Resize|sf::Style::Close, sf::ContextSettings(0, 0, 0, 3, 0)) {"<<std::endl;
                source<<"}"<<std::endl;
                source<<"void "<<appliname<<"::onLoad() {"<<std::endl;
                source<<"}"<<std::endl;
                source<<"void "<<appliname<<"::onInit() {"<<std::endl;
                source<<"}"<<std::endl;
                source<<"void "<<appliname<<"::onRender(RenderComponentManager *cm) {"<<std::endl;
                source<<"}"<<std::endl;
                source<<"void "<<appliname<<"::onDisplay(RenderWindow* window) {"<<std::endl;
                source<<"}"<<std::endl;
                source<<"void "<<appliname<<"::onUpdate (RenderWindow* window, sf::Event& event) {"<<std::endl;
                source<<" if (&getRenderWindow() == window && event.type == sf::Event::Closed) {"<<std::endl;
                source<<"  stop();"<<std::endl;
                source<<" }"<<std::endl;
                source<<"}"<<std::endl;
                source<<"void "<<appliname<<"::onExec () {"<<std::endl;
                source<<"}"<<std::endl;
                source.close();
                std::string width = taWidth->getText();
                std::string height = taHeight->getText();
                std::ofstream main(path+"/main.cpp");
                main<<"#include \""<<minAppliname<<".hpp\""<<std::endl;
                main<<"int main(int argc, char* argv[]) {"<<std::endl;
                main<<"    "<<appliname<<" app(sf::VideoMode("<<width<<","<<height<<"),\""<<appliname<<"\");"<<std::endl;
                main<<"    return app.exec();"<<std::endl;
                main<<"}"<<std::endl;
                main.close();
            }
        }
        if (button->getText() == "New texture") {
            fdTexturePath->setVisible(true);
            fdTexturePath->setEventContextActivated(true);
        }
    }
    La commande fonction mkdir échoue et ça m'affiche la création du dossier à échoué ressource temporairement indisponible. Ca veut dire quoi ?
    Le dossier est présent quand j'ouvre le gestionnaire de fichiers de linux mais aucun fichier dedans n'est créé.

  2. #2
    Modérateur
    Avatar de Obsidian
    Homme Profil pro
    Chercheur d'emploi
    Inscrit en
    Septembre 2007
    Messages
    7 462
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Chercheur d'emploi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2007
    Messages : 7 462
    Par défaut
    Il suffit de lire la man page : https://man.developpez.com/man2/mkdir/

    Citation Envoyé par man 2 mkdir
    mkdir() renvoie 0 s'il réussit, ou -1 s'il échoue, auquel cas errno contient le code d'erreur.

    Toi, tu as écrit

    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
            if(!mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
                std::cerr<<"Failed to create application directory!";

    Tu considères un code de retour nul comme une erreur alors que c'est le contraire.

    La commande fonction mkdir échoue et ça m'affiche la création du dossier à échoué ressource temporairement indisponible. Ca veut dire quoi ?
    Le dossier est présent quand j'ouvre le gestionnaire de fichiers de linux mais aucun fichier dedans n'est créé.
    « Ressource temporairement indisponible », c'est en général le code de retour EAGAIN, mais il ne fait pas partie des codes potentiellement renvoyés par mkdir(). Comme, de toutes façons, tu n'arrêtes pas ton programme après avoir détecté une erreur sur cet appel, le message que tu lis est vraissemblement produit par le std::cerr << "Error: " << strerror(errno);, situé trois lignes plus loin mais qui correspond à une opération complètement différente.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Ok super merci!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. problème d'appel d'une fonction d'une autre classe
    Par kifouillou dans le forum Langage
    Réponses: 5
    Dernier message: 08/02/2007, 17h42
  2. Réponses: 10
    Dernier message: 08/12/2006, 02h18
  3. [Système] Problème d'appel d'une fonction
    Par Ministar dans le forum Langage
    Réponses: 8
    Dernier message: 19/09/2006, 22h23
  4. problème avec l'appel d'une fonction
    Par mademoizel dans le forum ASP
    Réponses: 5
    Dernier message: 26/06/2006, 15h04
  5. Réponses: 7
    Dernier message: 12/03/2006, 21h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo