Welcome, Guest. Please login or register.

Author Topic: Quick question on C string comparison (resolved)  (Read 1698 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline LoadWBTopic starter

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Quick question on C string comparison (resolved)
« on: December 03, 2007, 08:18:33 AM »
I'm farting around with UW's imap kit, imap-2006i.  I want to have the syslog facility set based on the running service.

Here's the call to server_init() from imap.c:

  server_init (pgmname,"imap","imaps",clkint,kodint,hupint,trmint);


Here's the function definition from env_unix.c:

void server_init (char *server,char *service,char *sslservice,
                  void *clkint,void *kodint,void *hupint,void *trmint)


The line I'm trying to get to make work looks like this:

openlog (myServerName = cpystr (server), LOG_PID, (service=="imap") ? LOG_LOCAL2 : LOG_LOCAL0);


The ternary always returns the false value, LOG_LOCAL0.  It's been forever since I did anything useful with C... what am I missing here?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Quick question on C string comparison
« Reply #1 on: December 03, 2007, 08:21:38 AM »
service=="imap" does not compare strings, but string pointers.

look into strcmp.
 

Offline LoadWBTopic starter

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Re: Quick question on C string comparison
« Reply #2 on: December 03, 2007, 08:38:01 AM »
Bingo.  Darned pointers.  I knew I was missing something easy.

Piru, I *knew* you'd have the answer.  Thanks!  :pint:

This did it

openlog (myServerName = cpystr (server), LOG_PID, strcmp(service,"imap") ? LOG_LOCAL0 : LOG_LOCAL2 );

Now this is fixed, I need to get to bed.  Tomorrow I get to figure out what Mark changed in dmail between 2004f and 2006i so I can make port my symlink hack :-D