It's UWAweek 9 (1st semester, week 1)

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying selected article
Showing 1 of 1168 articles.
Currently 1 other person reading this forum.


 UWA week 39 (2nd semester, week 9) ↓
SVG not supported

Login to reply

👍?
helpful
4:01am Fri 29th Sep, Christopher M.

"Hugo Smith" <23*2*1*2@s*u*e*t*u*a*e*u*a*> wrote:
> Hey Chris > What's the maximum number of: > - files in a directory > - characters in a file/directory name > - directories specified in the command line > Cheers
Hi Hugo, I strongly suspect that you're asking for this information because you want to define fixed-sized arrays. However, that's the wrong approach for this project. Firstly, there are no guaranteed upper-bounds on these values (but one), and even trying to determine them could only be done in a very non-portable way. For example, while one system (even one version of the Linux kernel) may place an upper bound on the *total* size of a directory, the number of directory entries that can fit in that space will depend on what's being stored - lots of entries with very short names, or very few entries with very long names. Similarly, there is a limit on the combined maximum size of all command-line arguments and environment variables, which sits at the top of the stack (and from memory it's 2MB, but don't quote me). So, again, you can have many very short command-line arguments, or far fewer very long arguments, and the number of command-line arguments will be limited by the amount of memory already storing the environment variables. The kernel enforces and checks against these limits - for example, when calling exec() to load a new program, one of the possible errors is: E2BIG The total number of bytes in the environment (envp) and argument list (argv) is too large. But this 2nd project is different than the 1st - we don't wish to use fixed-sized arrays for everything, but strongly prefer (need) to employ dynamically allocated memory to store exactly what we need - if the command-line provides 4 directory names, we allocate memory for exactly 4 'things' to store those names, and further use strdup() to allocate exactly the needed memory for each name; if a directory has 83 directory entries, then we allocate memory for exactly 83 'things' to store the required information. ______ But there is one answer - the maximum size of any directory entry name (file or directory) is named MAXPATHLEN and is defined in <sys/param.h> on both Linux and macOS.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  5:07AM Sep 06 2023
Privacy policy