Sponsored Content
Full Discussion: Explanation of Inodes / path
Top Forums UNIX for Beginners Questions & Answers Explanation of Inodes / path Post 303019098 by murugesandins on Friday 22nd of June 2018 10:13:04 PM
Old 06-22-2018
Code:
// Written comment for new employees/joinees  and for me too :) => Better initialize
#include <string.h>    // strerror
#include <sys/errno.h> // errno
#include <unistd.h>    // getcwd
#include <stdio.h>     // printf
// PATH_LENGTH variaes on OS
// Change PATH_LENGTH based on macro, OS and requirement
// Example: What is the longest file path that Windows can handle? - Super User
// Written CYGWIN_NT since .exe can run outside bash.exe or sh.exe or mksh.exe or ...
// => gecwd error => Numerical result out of range
// getcwd will fail when length varies above expected lenth at windows
#ifdef CYGWIN_NT
        #define PATH_LENGTH 195
#else
        #define PATH_LENGTH 256
#endif
char cwd[PATH_LENGTH] = {};
char *PWD = NULL;
int main()
{
        PWD = getcwd(cwd, PATH_LENGTH);
        // value != variable to remove initialization by typewriting mistakes
        // Example: if( p = NULL )
        if( NULL != PWD )
        {
                printf("The current working directory is \"%s\"\n", cwd);
        }
        else
        {
                printf( "getcwd() failed.\n%s\n", strerror(errno));
                return 1;
        }
        return 0;
}

 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

INodes...

Could someone please explain to me the concept of INodes? Colour me a DOS/MacOS junkie, but I don't quite understand. Is there any relation to clusters, or physical distro.? ty. (3 Replies)
Discussion started by: boris888
3 Replies

2. Solaris

inodes???

Does anyone know what command I can run to check how many inodes are in use on a specific filesystem. On Data General servers I used to run the df -k command to check the status of the inodes for all file system.s (1 Reply)
Discussion started by: soliberus
1 Replies

3. Solaris

inodes

hi i need to find all the files that r linked to the current file as i need to delete the file as well as few of its links :confused: thnx in advance (1 Reply)
Discussion started by: livemyway
1 Replies

4. UNIX for Dummies Questions & Answers

inodes

how is the location of inodes in the physical disk. are they sequential like: bootblock|superblock|inode1|inode2| ....| datablock1|datablock2|datablock3 or are they distributed among data blocks like: bootblock|superblock|inode1|datablock1|inode2|datablock2|datablock3|inode3 |datablock4 (3 Replies)
Discussion started by: gfhgfnhhn
3 Replies

5. Linux

Inodes

Any good sites, tutorials that explain Inodes clearly and completely ? (3 Replies)
Discussion started by: nitin09
3 Replies

6. Solaris

Number of used inodes..?

Hello Experts How can i know Number of used and free inodes in a file system? thanx in advance.. (3 Replies)
Discussion started by: younus_syed
3 Replies

7. Solaris

Increasing inodes

Hi , Can someone help me to increase "inode" in solaris 9? Thanks in advance, Gowtham (8 Replies)
Discussion started by: gowthamakanthan
8 Replies

8. Filesystems, Disks and Memory

inodes

Hi, sorry to have written in other language i think i could do that. I would to know A file system use inodes indexed allocation as a method of allocating space. In the inode blocks are 10 references to direct, 1 indirect reference to a single block, 1 block indirect reference to a reference to... (1 Reply)
Discussion started by: maryprin
1 Replies

9. Solaris

/var: out of inodes

Dear Forum, Please help me i have SUNW,Sun-Fire-V240 with sun solaris 8,if i check inode in /var like below: # df -F ufs -o i Filesystem iused ifree %iused Mounted on /dev/md/dsk/d0 62354 310638 17% / /dev/md/dsk/d3 372992 0 100% /var... (2 Replies)
Discussion started by: fredginting
2 Replies

10. UNIX for Advanced & Expert Users

Help with Inodes please

How can i trace Inode structure and modify it in UNIX kernel? We want to change the inode structure in the sense that we want to add a new field to the inode data structure. So we want to know how and where to trace inode (7 Replies)
Discussion started by: Group_Inode
7 Replies
getcwd(3C)						   Standard C Library Functions 						getcwd(3C)

NAME
getcwd - get pathname of current working directory SYNOPSIS
#include <unistd.h> char *getcwd(char *buf, size_t size); DESCRIPTION
The getcwd() function places an absolute pathname of the current working directory in the array pointed to by buf, and returns buf. The pathname copied to the array contains no components that are symbolic links. The size argument is the size in bytes of the character array pointed to by buf and must be at least one greater than the length of the pathname to be returned. If buf is not a null pointer, the pathname is stored in the space pointed to by buf. If buf is a null pointer, getcwd() obtains size bytes of space using malloc(3C). The pointer returned by getcwd() can be used as the argu- ment in a subsequent call to free(). RETURN VALUES
Upon successful completion, getcwd() returns the buf argument. If buf is an invalid destination buffer address, NULL is returned and errno is set to EFAULT. Otherwise, a null pointer is returned and errno is set to indicate the error. ERRORS
The getcwd() function will fail if: EFAULT The buf argument is an invalid destination buffer address. EINVAL The size argument is equal to 0. ERANGE The size argument is greater than 0 and less than the length of the pathname plus 1. The getcwd() function may fail if: EACCES A parent directory cannot be read to get its name. ENOMEM Insufficient storage space is available. EXAMPLES
Example 1 Determine the absolute pathname of the current working directory. The following example returns a pointer to an array that holds the absolute pathname of the current working directory. The pointer is returned in the ptr variable, which points to the buf array where the pathname is stored. #include <stdlib.h> #include <unistd.h> ... long size; char *buf; char *ptr; size = pathconf(".", _PC_PATH_MAX); if ((buf = (char *)malloc((size_t)size)) != NULL) ptr = getcwd(buf, (size_t)size); ... Example 2 Print the current working directory. The following example prints the current working directory. #include <unistd.h> #include <stdio.h> main() { char *cwd; if ((cwd = getcwd(NULL, 64)) == NULL) { perror("pwd"); exit(2); } (void)printf("%s ", cwd); free(cwd); /* free memory allocated by getcwd() */ return(0); } USAGE
Applications should exercise care when using chdir(2) in conjunction with getcwd(). The current working directory is global to all threads within a process. If more than one thread calls chdir() to change the working directory, a subsequent call to getcwd() could produce unex- pected results. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
chdir(2), malloc(3C), attributes(5), standards(5) SunOS 5.11 18 Oct 2004 getcwd(3C)
All times are GMT -4. The time now is 05:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy