IRC channel logs

2020-01-28.log

back to list of logs

<fossy>i'm wondering what the best way to implement tests for chdir() would be to check that chdir() actually worked...
<fossy>oriansj: ^
<fossy>was thinking a /usr/bin/ls call but that wont work in the lower stages of the bootstrap
<fossy>also getcwd() will vary from system-to-system.. dont know how to do that one really either. i guess it would probably just be ensuring that it dosent error?
<dddddd>I was thinking something like: getcwd (note the result) chdir to subdir (we can provide it, already created) note that it changes correctly with another getcwd
<dddddd>maybe get back and recheck
<dddddd>just rough idea
<dddddd>Using the shell commands that call to those syscall, I mean.
<fossy>that's a good idea
<fossy>also does anyone know how the heck you can do pass by reference or pass by pointer in M2-Planet?? trying to do pass by reference int func(int* ptr) { &ptr = 1; } dosen't work... and pass by pointer int func(int& ref) { ref = 1; } dosen't work
<xentrac>*ptr = 1
<xentrac>&foo isn't an lvalue
<fossy>oh woops
<fossy>file.c:3:Received * in primary_expr
<fossy> https://ttm.sh/EqW.txt
<fossy>xentrac: not working...
<dddddd>I don't think *foo is supported. Neither any t& types.
<dddddd>I guess I'd pass a struct for the function to change data of the caller. Maybe share a global instead. What's the use-case? M2-Planet is not C.
<dddddd>just "happens to look and behave enough like C"
<dddddd>I can think of some asm() trickery, but that's nasty and non-portable.
<dddddd>nah, I don't think that would work.
<fossy>yeah i'm thinking to just use a global
<fossy>because you're right M2-Planet is a small subset of C
<fossy>oriansj: get_current_dir_name() returns a variable that when referenced segfaults the program
<oriansj>first there is no pass by references in M2-Planet and pass by pointer only works partially because there is no updating the caller from the callee. (aka passing struct foo* bar allows one to update the fields in bar but not change the value of bar in the caller.
<oriansj>it also would be ptr = 1; not *ptr = 1;
<oriansj>as M2-Planet doesn't support *foo = *bar; but it is possible do the same via: foo->a = bar->a; foo->b = bar->b; ... foo->N = bar->N
<oriansj>also, I never bothered to check what the getcwd syscall actually returns in RAX
<xentrac>t& types aren't in C
<oriansj>in which case if getcwd works but get_current_dir_name doesn't; I would just have to do char* ret = malloc(MAX_PATH); getcwd(ret, MAX_PATH); return ret;
<oriansj>well this passes as working: https://paste.debian.net/1127972/
<oriansj>buildable with the following:https://paste.debian.net/1127973/
<oriansj>hmmm, it looks like the syscall returns the number of chars in the pathname; rather than the string. Looks like my messy guess was wrong
<oriansj>and I need to change getcwd to return buf if NULL was not returned. Easy to fix.
<oriansj>I'll do that tomorrow if someone else doesn't do it while I sleep. Good night
<fossy>nini
<oriansj>odd that GCC gives me: error: ‘PATH_MAX’ undeclared
<oriansj>oh well, easy to work around
<oriansj>here is the new example case: https://paste.debian.net/1128025/
<oriansj>buildable via gcc with identical output
<oriansj>and the patch will be up shortly
<oriansj>if one uses the previously posted M2-Planet build script with the now up patch, you'll have it all working.
<oriansj>fossy: one minor note: it is int fchdir(int fd); instead of int fchdir(FILE* fd) because FILE is a struct with quite a few fields (including its file descriptor) and fchdir is just a wrapper for a syscall which knows nothing about that struct and just wants a file descriptor. Other than that it looks good.
<oriansj>and it looks like markjenkinsznc was kicking ass last night; good job
<dddddd>o/
***ng0_ is now known as ng0
<fossy>oriansj: ah, I thought it was a mistake
<fossy>oriansj: so how should you pass a FILE* to fchdir then
<fossy>which field does it want?