/[qemacs]/qemacs/cutils.c
ViewVC logotype

Diff of /qemacs/cutils.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by chqrlie, Tue Nov 30 10:18:00 2004 UTC revision 1.3 by chqrlie, Tue May 10 18:53:04 2005 UTC
# Line 93  void pstrcpy(char *buf, int buf_size, co Line 93  void pstrcpy(char *buf, int buf_size, co
93      if (buf_size <= 0)      if (buf_size <= 0)
94          return;          return;
95    
96      for(;;) {      for (;;) {
97          c = *str++;          c = *str++;
98          if (c == 0 || q >= buf + buf_size - 1)          if (c == 0 || q >= buf + buf_size - 1)
99              break;              break;
# Line 112  char *pstrcat(char *buf, int buf_size, c Line 112  char *pstrcat(char *buf, int buf_size, c
112      return buf;      return buf;
113  }  }
114    
115    /* copy the n first char of a string and truncate it. */
116    char *pstrncpy(char *buf, int buf_size, const char *s, int len)
117    {
118        char *q;
119        int c;
120    
121        if (buf_size > 0) {
122            q = buf;
123            if (len >= buf_size)
124                len = buf_size - 1;
125            while (len > 0) {
126                c = *s++;
127                if (c == '\0')
128                    break;
129                *q++ = c;
130                len--;
131            }
132            *q = '\0';
133        }
134        return buf;
135    }
136    
137  #endif  #endif
138    
139  /**  /**

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26