dtcm: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtcm / libDtCmP / util.c
index 57a21630b75d474b28fc1eabe308cb89e8a6e912..537d1b69837eec5a8670117e486afed4bd3a0616 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <pwd.h> 
 #include <netdb.h> 
 #include <sys/utsname.h> /* SYS_NMLN */
-#if defined(sun) || defined(USL) || defined(__uxp__)
+#if defined(sun)
 #include <sys/systeminfo.h>
+#elif defined(CSRG_BASED)
+#include <sys/dirent.h>
 #else
 #include <sys/dir.h>
-#endif /* sun || USL || __uxp__ */
+#endif /* sun */
 #include <sys/param.h>
 
-#if (defined(USL) || defined(__uxp__)) && !defined(DOM_NM_LN)
-#define DOM_NM_LN  BUFSIZ
-#endif
-
 #define X_INCLUDE_STRING_H
 #define X_INCLUDE_TIME_H
 #define XOS_USE_NO_LOCKING
+#if defined(__linux__)
+#undef SVR4
+#endif
 #include <X11/Xos_r.h>
 
 #include <errno.h>
@@ -100,7 +102,7 @@ extern int          pclose(FILE *);
  *
  */
 extern char*
-cm_def_printer()
+cm_def_printer(void)
 {
         FILE *fp;
         char message[257];
@@ -143,7 +145,7 @@ cm_def_printer()
        }
 #else
        tmp = (char*)getenv("PRINTER");
-       if (tmp != NULL && *tmp != NULL) {
+       if (tmp != NULL && *tmp != '\0') {
                printer_name = (char*)malloc(strlen(tmp)+1);
                strcpy(printer_name, tmp);
        }
@@ -184,7 +186,7 @@ cm_strlen(register char *s)
 {
         register int n;
  
-       if (s==NULL) return NULL;
+       if (s==NULL) return 0;
        return (strlen(s));
 }
 
@@ -243,7 +245,7 @@ str_to_cr(char *s)
                 }
                 k++;
         }
-        newstr[k] = NULL;
+        newstr[k] = '\0';
         return(newstr);
 }
 
@@ -283,14 +285,13 @@ cr_to_str(char *s)
                        k++;
                }
        }
-       newstr[k] = NULL;
+       newstr[k] = '\0';
        return(newstr);
 }
 
 /* VARARGS1 */
 extern void
-syserr(msg, a1, a2, a3)
-       char *msg;
+syserr(char *msg, int a1, int a2, int a3)
 {
        /* Taken from Unix World, July 1989, p. 66 */
        int saveerr;
@@ -501,7 +502,7 @@ get_head(char *str, char sep)
         if (ptr == buf)
                 return(NULL);
         else {
-                *ptr = NULL;
+                *ptr = '\0';
                 return(cm_strdup(buf));
         }
 }
@@ -523,7 +524,7 @@ get_tail(char *str, char sep)
 }
 
 extern char *
-cm_get_credentials()
+cm_get_credentials(void)
 {
        char *name, *host;
        static char *login = NULL;
@@ -539,24 +540,24 @@ cm_get_credentials()
 }
 
 extern char *
-cm_get_local_host()
+cm_get_local_host(void)
 {
        static char *local_host;
 
         if (local_host == NULL) {
-#if defined(sun) || defined(USL) || defined(__uxp__)
+#if defined(sun)
                 local_host = (char *)ckalloc(MAXHOSTNAMELEN);
                 (void) sysinfo(SI_HOSTNAME, local_host, MAXHOSTNAMELEN);
 #else
                 local_host = (char *)ckalloc(MAXHOSTNAMELEN);
                 (void) gethostname(local_host, MAXHOSTNAMELEN);
-#endif /* sun || USL || __uxp__ */
+#endif /* sun */
         }
         return local_host;
 }
 
 extern char *
-cm_get_uname()
+cm_get_uname(void)
 {
         static char *name;
         struct passwd *pw; 
@@ -572,17 +573,20 @@ cm_get_uname()
 }
 
 extern char *
-cm_get_local_domain()
+cm_get_local_domain(void)
 {
        static char *local_domain;
 
         if (local_domain == NULL) {
                 local_domain = ckalloc(BUFSIZ);
-#if defined(sun) || defined(USL) || defined(__uxp__)
+#if defined(sun)
                 sysinfo(SI_SRPC_DOMAIN, local_domain, DOM_NM_LN);
 #else
-               (void) getdomainname(local_domain, BUFSIZ);
-#endif /* sun || USL || __uxp__ */
+               if(-1 == getdomainname(local_domain, BUFSIZ)) {
+                       fprintf(stderr, "getdomainname() failed %d '%s'\n", errno, strerror(errno));
+               }
+               
+#endif /* sun */
        }
         return(local_domain);
 }
@@ -730,10 +734,10 @@ match_forward(char *str1, char *str2)
                get_component(&str2, com2, '.');
 
                if (*com1) {
-                       if (*com2 == NULL)
+                       if (*com2 == '\0')
                                return (B_TRUE);
                } else {
-                       if (*com2 == NULL)
+                       if (*com2 == '\0')
                                return (B_TRUE);
                        else
                                return (B_FALSE);
@@ -744,18 +748,18 @@ match_forward(char *str1, char *str2)
 
                /* take care of case: a.b a. */
                if (strcmp(str2, ".") == 0
-                   && (strcmp(str1, ".") != 0 || *str1 != NULL))
+                   && (strcmp(str1, ".") != 0 || *str1 != '\0'))
                        return (B_FALSE);
 
                /* skip "." */
                if (*str1 == '.') {
-                       if (*str2 == NULL)
+                       if (*str2 == '\0')
                                return (B_TRUE);
                        else {
                                str1++;
                                str2++;
                        }
-               } else if (strcmp(str2, ".") == 0 || *str2 == NULL)
+               } else if (strcmp(str2, ".") == 0 || *str2 == '\0')
                        return (B_TRUE);
                else
                        return (B_FALSE);
@@ -793,10 +797,10 @@ match_backward(char *str1, char *str2)
                get_last_component(str2, &ptr2, com2, '.');
 
                if (*com1) {
-                       if (*com2 == NULL)
+                       if (*com2 == '\0')
                                return (B_TRUE);
                } else {
-                       if (*com2 == NULL)
+                       if (*com2 == '\0')
                                return (B_TRUE);
                        else
                                return (B_FALSE);
@@ -1038,9 +1042,9 @@ parse_date(OrderingType order, SeparatorType sep, char *datestr, char *m,
         char *tmp_date, *str = separator_str(sep);
        _Xstrtokparams strtok_buf;
  
-        m[0] = NULL;
-        d[0] = NULL;
-        y[0] = NULL;
+        m[0] = '\0';
+        d[0] = '\0';
+        y[0] = '\0';
  
         if (datestr == NULL)
                 return 0;
@@ -1095,7 +1099,7 @@ extern int
 datestr2mdy(char *datestr, OrderingType order, SeparatorType sep, char *buf) {
         char m[3], d[3], y[5];
  
-        buf[0] = NULL;
+        buf[0] = '\0';
         if (datestr == NULL)
                 return 0;
  
@@ -1121,7 +1125,7 @@ format_tick(Tick tick, OrderingType order, SeparatorType sep, char *buff) {
         struct tm      *tm;
        _Xltimeparams   localtime_buf;
  
-        buff[0] = NULL;
+        buff[0] = '\0';
         tm = _XLocaltime(&tick, localtime_buf);
  
         switch (order) {
@@ -1147,7 +1151,7 @@ format_time(Tick t, DisplayType dt, char *buffer) {
        boolean_t       am;
 
        if (t == 0) {
-               sprintf(buffer, "\0");
+               buffer[0] = '\0';
 
        } else if (dt == HOUR12) {
                am = adjust_hour(&hr);
@@ -1231,7 +1235,7 @@ Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, .
         */
        idx = sizeof(Dtcm_appointment);
        appt = (Dtcm_appointment *)ckalloc(idx);
-       memset(appt, NULL, idx);
+       memset(appt, 0, idx);
        appt->reason = reason;
        appt->version = version;
 
@@ -1243,7 +1247,7 @@ Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, .
        api_idx = va_arg(pvar, int);
        while (api_idx) {
                if ((reason == appt_read) || !entry_ident_index_ro(api_idx, version))
-                       CmDataListAdd(api_ids, (void *)api_idx, 0);
+                       CmDataListAdd(api_ids, (void *) (intptr_t) api_idx, 0);
                api_idx = va_arg(pvar, int);
        }
        va_end(pvar);
@@ -1265,7 +1269,7 @@ Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, .
                for (idx = 0; idx < def_attr_count; idx++) {
                        if ((reason == appt_write) && entry_ident_index_ro(default_appt_attrs[idx], version))
                                continue;
-                       CmDataListAdd(api_ids, (void *)default_appt_attrs[idx], 0);
+                       CmDataListAdd(api_ids, (void *) (intptr_t) default_appt_attrs[idx], 0);
                }
        }
 
@@ -1278,20 +1282,20 @@ Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, .
        appt->num_names = api_ids->count;
        idx = sizeof(CSA_attribute_reference *) * appt->num_names;
        appt->names = (CSA_attribute_reference *)ckalloc(idx);
-       memset(appt->names, NULL, idx);
+       memset(appt->names, 0, idx);
 
        appt->count = api_ids->count;
        if (reason == appt_write) {
                idx = sizeof(CSA_attribute) * appt->count;
                appt->attrs = (CSA_attribute *)ckalloc(idx);
-               memset(appt->attrs, NULL, idx);
+               memset(appt->attrs, 0, idx);
        }
 
        /*
         * Now loop through and set the names and initialize the attributes
         */
        for (idx = 0; idx < appt->count; idx++) {
-               api_idx = (int)CmDataListGetData(api_ids, idx + 1);
+               api_idx = (int) (intptr_t) CmDataListGetData(api_ids, idx + 1);
                appt->names[idx] = strdup(_CSA_entry_attribute_names[api_idx]);
                if (reason == appt_write)
                        initialize_entry_attr(api_idx, &appt->attrs[idx], reason, version);
@@ -1300,7 +1304,7 @@ Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, .
        if (reason == appt_write)
                set_appt_links(appt);
 
-       CmDataListDestroy(api_ids, NULL);
+       CmDataListDestroy(api_ids, 0);
        return appt;
 }
 
@@ -1353,7 +1357,7 @@ allocate_cal_struct(Allocation_reason reason, int version, ...) {
         */
        idx = sizeof(Dtcm_calendar);
        cal = (Dtcm_calendar *)ckalloc(idx);
-       memset(cal, NULL, idx);
+       memset(cal, 0, idx);
        cal->reason = reason;
        cal->version = version;
 
@@ -1365,7 +1369,7 @@ allocate_cal_struct(Allocation_reason reason, int version, ...) {
        api_idx = va_arg(pvar, int);
        while (api_idx) {
                if ((reason == appt_read) || !cal_ident_index_ro(api_idx, version))
-                       CmDataListAdd(api_ids, (void *)api_idx, 0);
+                       CmDataListAdd(api_ids, (void *) (intptr_t) api_idx, 0);
                api_idx = va_arg(pvar, int);
        }
        va_end(pvar);
@@ -1377,7 +1381,7 @@ allocate_cal_struct(Allocation_reason reason, int version, ...) {
                for (idx = 0; idx < DEF_CAL_ATTR_COUNT; idx++) {
                        if ((reason == appt_write) && cal_ident_index_ro(default_cal_attrs[idx], version))
                                continue;
-                       CmDataListAdd(api_ids, (void *)default_cal_attrs[idx], 0);
+                       CmDataListAdd(api_ids, (void *) (intptr_t) default_cal_attrs[idx], 0);
                }
        }
 
@@ -1390,20 +1394,20 @@ allocate_cal_struct(Allocation_reason reason, int version, ...) {
        cal->num_names = api_ids->count;
        idx = sizeof(CSA_attribute_reference) * cal->num_names;
        cal->names = (CSA_attribute_reference *)ckalloc(idx);
-       memset(cal->names, NULL, idx);
+       memset(cal->names, 0, idx);
 
        cal->count = api_ids->count;
        if (reason == appt_write) {
                idx = sizeof(CSA_attribute) * cal->count;
                cal->attrs = (CSA_attribute *)ckalloc(idx);
-               memset(cal->attrs, NULL, idx);
+               memset(cal->attrs, 0, idx);
        }
 
        /*
         * Now loop through and set the names and initialize the attributes
         */
        for (idx = 0; idx < cal->count; idx++) {
-               api_idx = (int)CmDataListGetData(api_ids, idx + 1);
+               api_idx = (int) (intptr_t) CmDataListGetData(api_ids, idx + 1);
                cal->names[idx] = strdup(_CSA_calendar_attribute_names[api_idx]);
                if (reason == appt_write)
                        initialize_cal_attr(api_idx, &cal->attrs[idx], reason, version);
@@ -1412,7 +1416,7 @@ allocate_cal_struct(Allocation_reason reason, int version, ...) {
        if (reason == appt_write) 
                set_cal_links(cal);
 
-       CmDataListDestroy(api_ids, NULL);
+       CmDataListDestroy(api_ids, 0);
 
 
        return cal;
@@ -1452,7 +1456,7 @@ scrub_cal_attr_list(Dtcm_calendar *cal) {
        for (i = 0; i < cal->count; i++) {
                if (cal->attrs[i].value->type == CSA_VALUE_REMINDER) {
                        if ((cal->attrs[i].value->item.reminder_value->lead_time == NULL) || 
-                            (cal->attrs[i].value->item.reminder_value->lead_time[0] == NULL)) {
+                            (cal->attrs[i].value->item.reminder_value->lead_time[0] == '\0')) {
                                free(cal->attrs[i].name);
                                cal->attrs[i].name = NULL;
                        }
@@ -1662,7 +1666,7 @@ initialize_cal_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int
        if ((reason == appt_write) && !cal_ident_index_ro(id, version)) {
                size = sizeof(CSA_attribute_value);
                attrs->value = (CSA_attribute_value *)ckalloc(size);
-               memset(attrs->value, NULL, size);
+               memset(attrs->value, 0, size);
                attrs->value->type = cal_ident_index_tag(id);
                if (attrs->value->type == CSA_VALUE_REMINDER)
                        attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
@@ -1706,7 +1710,7 @@ initialize_entry_attr(int id, CSA_attribute *attrs, Allocation_reason reason, in
        if ((reason == appt_write) && !entry_ident_index_ro(id, version)) {
                size = sizeof(CSA_attribute_value);
                attrs->value = (CSA_attribute_value *)ckalloc(size);
-               memset(attrs->value, NULL, size);
+               memset(attrs->value, 0, size);
                attrs->value->type = entry_ident_index_tag(id);
                if (attrs->value->type == CSA_VALUE_REMINDER)
                        attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
@@ -1897,11 +1901,11 @@ setup_range(CSA_attribute **attrs, CSA_enum **ops, int *count, time_t start,
 
        a_size = sizeof(CSA_attribute) * (*count);
        attr_ptr = (CSA_attribute *)ckalloc(a_size);
-       memset(attr_ptr, NULL, a_size);
+       memset(attr_ptr, 0, a_size);
 
        o_size = sizeof(CSA_enum) * (*count);
        op_ptr = (CSA_enum *)ckalloc(o_size);
-       memset(op_ptr, NULL, o_size);
+       memset(op_ptr, 0, o_size);
 
        initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[0], appt_write, version);
        attr_ptr[0].value->item.string_value = malloc(BUFSIZ);