I'm leaving the other bits in for those who like the whole story.

This works:

          { // validate program name
                struct stat statbuf;
                int statret=stat(program.data(),&statbuf);
                if (statret == -1)
                  {
                        cerr << "error checking program \"" << program << "\" using 
stat(): " << 
strerror(errno) << endl;
                  } else if (!S_ISREG(statbuf.st_mode))
                        {
                          cerr << program << " is not a regular file." << endl;
                          err=max(2,err);
                        } else if (!(statbuf.st_mode & 0111)) 
                          {
                                cerr << program << " is not an executable  file." << 
endl;
                                err=max(2,err);
                          }
          }


the group code is a copy&past&patch version.

According to the C++ primer which I have before me,
The data() method returns  a pointer to the first element of a string formed 
by copying elements from the range [begin,end).

(the broken bracket/parentheses pairing belongs to the book too).

The compiler does not comment on these code fragment.


Someone commented offlist (I really would prefer folk to stay on so others 
know everything that's said) on my (mis)use off errno.

At the point it takes that code, something's wrong, and there is a defined 
error that can occur.

To satisfy his curiosity I specifically set errno=0 immediately before the 
struct group and get the same results.






> John Summerfield wrote:
> > 
> > I have a code fragment:
> >                 struct group *grp = getgrnam(group.data());
> >                 if (grp == NULL)
> >                   {
> >                         int E=errno;
> >                         cerr << "error=" << E << ": " << strerror(E) << " "
>  << ENOMEM<< endl;;
> >                         cerr << "group " << group << " is unknown on this s
> ystem." << endl;
> >                         err=max(1,err);
> >                   }
> >                 else
> >                   {
> >                         gid = grp->gr_gid;
> >                   }
> 
> I tried it using C, and it worked fine.
> 
> -------------
> #include <stdio.h>
> #include <string.h>
> #include <grp.h>
> #include <sys/types.h>
> #include <errno.h>
> 
> main ( int argv, char *argc[])
> {
>    struct group *grp;
>    char *gum;
> 
>    gum=argc[1];
>    grp=getgrnam(gum);
>    if (grp == NULL)
>    {
>       printf("error %d : %s \n", errno, strerror(errno));
>       printf(" group %s\n", gum);
>    }
>    else
>       printf ("group %s : gid %d\n",gum, grp->gr_gid);
> }
> ---------------
> 
> This returned the correct results for /etc/group
> and the NIS group entries.
> 
> What does group.data() return?
> Is it a char* or a C++ string?
> Is there an auto cast for this?
> 
> In the error message you use group
> as the string. should you i]use it instead of
> the data() method?
> 
>       -Thomas
> 
> 
> 
> _______________________________________________
> Redhat-devel-list mailing list
> [EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/redhat-devel-list
> 

-- 
Cheers
John Summerfield
http://www2.ami.com.au/ for OS/2 & linux information.
Configuration, networking, combined IBM ftpsites index.

Microsoft's most solid OS: http://www.geocities.com/rcwoolley/

Note: mail delivered to me is deemed to be intended for me, for my disposition.





_______________________________________________
Redhat-devel-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

Reply via email to