Homebrew FSUSER_OpenFileDirectly compile error

tibinago

New Member
OP
Newbie
Joined
May 12, 2020
Messages
4
Trophies
0
Age
23
XP
34
Country
Germany
Hi again,

I am very new to coding hence why I asked a simiular question yesterday. To start learning to code I thought I'd take a source code and try to add some simple stuff to that.
I used 3DSController 0.6 for that because I thought some simple changes would make it better for me.

It turned out that the code is outdated especially functions that used ctrtulib. With some fiddling around I managed to update the code and reduce the errors to just one but this one gave me headaches.

I have trouble getting FSUSER_OpenFileDirectly to work.
Attached you can find the error messages.

By removing the '&' in front of &fileHandle the first error gets fixed, but is that the right way?
Secondly smdcArchive gets an error aswell but I cant figure out how to fix it. Examples I found on the internet unfortunately didn't help me. Any ideas?


Btw does anybody know a good way to learn to code? I have some very basic (pun intended) java experience from highschool but that's about it.


Thank you in advance!


This is settings.c

Code:
#include <stdio.h>
#include <malloc.h>

#include <3ds.h>

#include "wireless.h"

#include "settings.h"

struct settings settings;

struct settings defaultSettings = {
    IPString: "",
    port: DEFAULT_PORT,
};

Handle fileHandle;

static bool getSetting(char *name, char *src, char *dest) {
    char *start = strstr(src, name);
    
    if(start) {
        start += strlen(name);
        
        char *end = start + strlen(start);
        if(strstr(start, "\n") - 1 < end) end = strstr(start, "\n") - 1;
        size_t size = (size_t)end - (size_t)start;
        
        strncpy(dest, start, size);
        dest[size] = '\0';
        
        return true;
    }
    
    return false;
}

bool readSettings(void) {
    char *buffer = NULL;
    u64 size;
    u32 bytesRead;
    
    FS_Archive sdmcArchive = (FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
    FS_Path filePath = FS_makePath(PATH_BINARY, "/3DSController.ini");
    
    Result ret = FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_HIDDEN);
    if(ret) return false;
    
    ret = FSFILE_GetSize(fileHandle, &size);
    if(ret) return false;
    
    buffer = malloc(size);
    if(!buffer) return false;
    
    ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
    if(ret || size != bytesRead) return false;
    
    ret = FSFILE_Close(fileHandle);
    if(ret) return false;
    
    memcpy(&settings, &defaultSettings, sizeof(struct settings));
    
    char setting[64] = { '\0' };
    
    if(getSetting("IP: ", buffer, settings.IPString)) {
        //inet_pton(AF_INET, settings.IPString, &(saout.sin_addr));
        inet_pton4(settings.IPString, (unsigned char *)&(saout.sin_addr));
    }
    else {
        free(buffer);
        return false;
    }
    
    if(getSetting("Port: ", buffer, setting)) {
        sscanf(setting, "%d", &settings.port);
    }
    
    free(buffer);
    
    return true;
}
 

Attachments

  • error.PNG
    error.PNG
    82.2 KB · Views: 274

MasterFeizz

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
1,098
Trophies
1
Age
29
XP
3,710
Country
United States
There is a sticky development thread where you can ask question, you don't need to create a new post every time.

Basically you're going to have to find some c lessons on the internet. The compiler is literally highlighting the problems for you.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: @SylverReZ, lol +1