Changeset 29 for trunk/pbs_drmaa/util.c
- Timestamp:
- 10/17/11 01:49:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/pbs_drmaa/util.c
r16 r29 73 73 fsd_free( p ); 74 74 } 75 } 76 77 struct attrl * 78 pbsdrmaa_add_attr( struct attrl *head, const char *name, const char *value) 79 { 80 struct attrl *p = NULL; 81 char *resource = NULL; 82 83 fsd_malloc( p, struct attrl ); 84 memset( p, 0, sizeof(struct attrl) ); 85 86 resource = strchr( name, '.' ); 87 88 if( resource ) 89 { 90 p->name = fsd_strndup( name, resource - name ); 91 p->resource = fsd_strdup( resource+1 ); 92 } 93 else 94 { 95 p->name = fsd_strdup( name ); 96 } 97 98 p->value = fsd_strdup(value); 99 p->op = SET; 100 101 fsd_log_debug(("set attr: %s = %s", name, value)); 102 103 if (head) 104 p->next = head; 105 else 106 p->next = NULL; 107 108 return p; 75 109 } 76 110 … … 247 281 } 248 282 249 ssize_t fsd_getline(char * line,ssize_t size, int fd) 250 { 251 char buf; 252 char * ptr = NULL; 253 ssize_t n = 0, rc; 254 ptr = line; 255 for(n = 1; n< size; n++) 256 { 257 if( (rc = read(fd,&buf,1 )) == 1) { 258 *ptr++ = buf; 259 if(buf == '\n') 260 { 261 break; 262 } 263 } 264 else if (rc == 0) { 265 if (n == 1) 266 return 0; 267 else 268 break; 269 } 270 else 271 return -1; 272 } 273 274 return n; 275 } 276 277 ssize_t fsd_getline_buffered(char * line,char * buf, ssize_t size, int fd, int * idx, int * end_idx, int * line_idx) 278 { 279 int i = -1; 280 int rc = -1; 281 282 memset(line,0,size); 283 284 start: 285 /* idx - start of data to parse (in buffer) 286 end_idx - end of data read from log (in buffer) 287 line_idx - place to write data in output line */ 288 if(*idx < *end_idx) 289 { 290 /* take line from buffer */ 291 for(i = *idx; i<= *end_idx;i++) 292 { 293 if(buf[i] == '\n') 294 { 295 int tmp = i - *idx; 296 strncpy(line + *line_idx,buf + *idx,tmp); 297 *idx = i + 1; 298 299 tmp+= *line_idx; 300 *line_idx = 0; 301 302 return tmp; 303 } 304 } 305 306 /* there was no '\n' so next part of log needs to be read. save lines beginning */ 307 if(*line_idx + i - *idx > size ) 308 fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Line longer than %d unsupported",size); 309 310 strncpy(line + *line_idx,buf + *idx,i - *idx); 311 *line_idx += i - *idx; 312 *idx = 0; 313 *end_idx = 0; 314 goto start; 315 } 316 else 317 { 318 /* read log */ 319 if((rc = read(fd,buf,size)) > 0) 320 { 321 *end_idx = rc - 1; 322 *idx = 0; 323 goto start; 324 } 325 else if (rc == 0) 326 return 0; 327 else 328 return -1; 329 } 330 } 331 283
Note: See TracChangeset
for help on using the changeset viewer.