Browsing directories on remote linux server in C - c

On a local computer you can make use of the dirent.h library in C to browse files and folders. How would you do this on a remote linux computer? Would you pipe the readdir() commands through an ssh connection? I would like to achieve this without using any non-standard libraries.

Use an SSH library like libssh.
http://api.libssh.org/stable/
It includes an API for SFTP and SCP which are the file manipulation components of SSH.
http://api.libssh.org/stable/group__libssh__sftp.html
There is a tutorial available here:
http://api.libssh.org/master/libssh_tutor_sftp.html
There is example code for "Listing the contents of a directory" in that linked page.
I would like to achieve this without using any non-standard libraries.
That just isn't feasible. While the libraries included in your Linux distribution (including source header files and directly linkable blobs) probably do include libssh owing to its ubiquity, it isn't "standard" because the C standard library doesn't mention SSH/SFTP (or even have a file-system API!) nor does POSIX.
SSH (and SFTP) is a relatively recent protocol - it was only created in 1995 and didn't see wide adoption until the late-1990s (people were still using rlogin, rsh, standard FTP, or even TELNET) - it's predated by FTP, HTTP, SMTP, and SSL/TLS.
(Remember C is very minimal - my perception is that it's a language used to manipulate and iterate over memory - everything else, even syscalls, are not part of the C standard - which is why you can compile C to JavaScript, for example, you just can't do anything fun because you can't syscall from JavaScript)

Related

What is the equivalent of LoadString function in Linux?

LoadString function defined in windows can be used to load strings from a resource like dll or exe.
What is the LoadString equivalent function in Linux?
As noted in the comments, there is no single Linux operating system support for extracting resources from executables. There are multiple option in Linux for Internationalization (i18n), Localization (l10n) which may address your requirements.
Depending on your goals (externalization of messages, support for i18n, ...), similar functionality exists in different programming languages:
Java has resources (which can be added into JAR files),
LIBC provides gettext (via external message file ".po" files). See https://en.wikipedia.org/wiki/Gettext
Many scripting environment (python, perl) provide interfaces to gettext via modules.
Most GUI based frameworks have support for external resources (Gnome, Xt/X11, ...)
As a side note, it is possible to implement "LoadString", assuming messages are complied into the executable (as "C" code, or similar), using the dlsym dynamic lookup. Probably a last resort option.

decompressing tar.gz in rtems operating system

I was wondering if there was a specific set of library that can decompress tar.gz files in an rtems operating system. Most of the answer I seen is for linux. I was looking at gzip and libz but was not sure if these were for linux or can I use them for rtems as well.
There are some integrated functions that can extract tgz files in RTEMS. Take a look at the tar01 test for some examples with different sources (memory or file): https://git.rtems.org/rtems/tree/testsuites/libtests/tar01/init.c?id=8d989c56ff0c65beb7ec3390aebef6ea52840fab
Note that this is a test application intended to test the functionality. So some things might try to trigger expected failures. The test tar file is automatically generated by the Makefile, translated into some object file and linked into the application.
There is also the tarfs that can use a tar (not sure about tgz) as a read only file system. It's used in tar02 test.
Regarding libz: Although I haven't tried I would expect that it is possible to compile libz for RTEMS. If you need specifically that library you might want to ask on the RTEMS users mailing list whether someone already did that. There are a lot more RTEMS specific users and developers than on stackoverflow.

Cross-Platform API to monitor file system in C?

I'm looking for a cross platform library to detect when files in a directory are added or modified.
I know there are OS specific way to do this (inotify for Linux, FindFirstChangeNotification for windows, etc...).
But is there a platform independent library that works specifically in C? (Like the QFileSystemWatcher in C++)
inotify is Linux specific, if you want some UNIX portable features you are pobably looking for something like libfam. it is name of library. Full package name is fileschanged.
fileschanged is a GNU/Linux command-line utility that reports when files have been altered.
It's now 2021 so maybe septag/dmon is your cup of tea.
From the description:
Single header C99 portable library for monitoring directory changes
... or maybe the more beefy fswatch ?
Sounds like a good use case for golang.
Simply change $GOOS and/or $GOARCH and run go build.
Boom - trivial cross-platform development.

How to create a mountable file system?

This is just for self-study purpose.
In Windows, Linux or Mac, we can mount many kinds of file system (including SAMBA, Google drive file system, etc) and access them as if there were ordinary files and folders in the hard disk. How to create such file system? I am referring to the file system itself, not to the server where the files are stored.
I prefer if the tutorial is for Mac or Linux (I would guess that the technique will be OS dependent)
This is not as trivial as you might think.
I had to do this some time ago. What I did was to integrate a TCP/IP-based file server into my program and used the network file system functionality of the OS.
Today the "FUSE" project is available for Linux (and as far as I understand correctly) for MacOS X (the last one seems to be named "MacFUSE").
The "FUSE" project provides you a special API which allows you to create a mountable file system...
You install "FUSE" and you can write programs that provide file systems to the OS.

Choose interpreter TCL C API

I have a couple tcl interpreters on my system and i'd like to pick which one the C API for tcl uses. Is there a way to do this?
Thanks!
The C api doesn't pick the interpreter, you pick the C api corresponding to the interpreter you wish to use, by changing the include and link paths.
You pass the interpreter to the C API, having first created it with Tcl_CreateInterp. For example Tcl_Eval's interface is:
int Tcl_Eval(Tcl_Interp *interp, const char *script)
Generally speaking, when running a Tcl program you pick the API by selecting the interpreter. You can do this explicitly by naming the interpreter program as exactly as you choose:
bash$ /my/special/place/bin/tclsh8.6 thescript.tcl ...
Or you can put this trick with the standard env program at the start your executable Tcl script and rely on the OS to process your PATH environment to select a suitable one:
#!/usr/bin/env tclsh8.6
It's standard to install Tcl interpreters with the version in their names so that you can easily have different versions on the system.
When creating a C program that uses the Tcl library, you select the headers and libraries (which are usually best regarded as a matched set) by setting your include and library path. Unix compilers usually use -I and -L options to do that respectively; a script (tclConfig.sh) is typically also installed to make getting those options right easier. Note that while Tcl's libraries are usually versioned in their names, Tcl's header files are not; if you install multiple versions of the headers into the same place, only the most recent version will be usable.
It's possible to use standard options to configure when building Tcl to make everything split up better.

Resources