]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/widechar/lib_cchar.c
ncurses 5.7 - patch 20091114
[ncurses.git] / ncurses / widechar / lib_cchar.c
index b6458ee4a1f406870a5b8bf33582c5f27c5bb2d0..478f284ce86c639f050af7a0f5548a5e15efe86d 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2001-2004,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,7 +35,7 @@
 
 #include <curses.priv.h>
 
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_cchar.c,v 1.11 2005/01/29 21:29:16 tom Exp $")
+MODULE_ID("$Id: lib_cchar.c,v 1.16 2009/10/24 23:21:31 tom Exp $")
 
 /* 
  * The SuSv2 description leaves some room for interpretation.  We'll assume wch
 
 /* 
  * The SuSv2 description leaves some room for interpretation.  We'll assume wch
@@ -50,12 +50,13 @@ setcchar(cchar_t *wcval,
         short color_pair,
         const void *opts)
 {
         short color_pair,
         const void *opts)
 {
-    int i;
-    int len;
+    unsigned i;
+    unsigned len;
     int code = OK;
 
     int code = OK;
 
-    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%ld,%d,%p)"),
-                     wcval, _nc_viswbuf(wch), attrs, color_pair, opts));
+    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"),
+                     (void *) wcval, _nc_viswbuf(wch),
+                     (unsigned long) attrs, color_pair, opts));
 
     len = wcslen(wch);
     if (opts != NULL
 
     len = wcslen(wch);
     if (opts != NULL
@@ -103,7 +104,11 @@ getcchar(const cchar_t *wcval,
     int code = ERR;
 
     TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
     int code = ERR;
 
     TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
-                     wcval, wch, attrs, color_pair, opts));
+                     (const void *) wcval,
+                     (void *) wch,
+                     (void *) attrs,
+                     (void *) color_pair,
+                     opts));
 
     if (opts == NULL) {
        len = (wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
 
     if (opts == NULL) {
        len = (wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
@@ -111,7 +116,11 @@ getcchar(const cchar_t *wcval,
            : CCHARW_MAX;
 
        if (wch == NULL) {
            : CCHARW_MAX;
 
        if (wch == NULL) {
-           code = len;
+           /*
+            * If the value is a null, set the length to 1.
+            * If the value is not a null, return the length plus 1 for null.
+            */
+           code = (len < CCHARW_MAX) ? (len + 1) : CCHARW_MAX;
        } else if (attrs == 0 || color_pair == 0) {
            code = ERR;
        } else if (len >= 0) {
        } else if (attrs == 0 || color_pair == 0) {
            code = ERR;
        } else if (len >= 0) {