~ubuntu-branches/ubuntu/precise/gnustep-base/precise

« back to all changes in this revision

Viewing changes to Source/NSData.m

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-07-05 09:49:51 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080705094951-gs19i3erqo2xx6if
Tags: 1.16.1-2ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  + debian/rules:
    - Add lpia to ALL_ARCHS supported architectures.
  + debian/control:
    - Add lpia architecture where needed.
  + debian/control{,.m4}:
    - Update Maintainer field as per spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   This library is free software; you can redistribute it and/or
12
12
   modify it under the terms of the GNU Lesser General Public
13
13
   License as published by the Free Software Foundation; either
14
 
   version 3 of the License, or (at your option) any later version.
 
14
   version 2 of the License, or (at your option) any later version.
15
15
 
16
16
   This library is distributed in the hope that it will be useful,
17
17
   but WITHOUT ANY WARRANTY; without even the implied warranty of
24
24
   Boston, MA 02111 USA.
25
25
 
26
26
   <title>NSData class reference</title>
27
 
   $Date: 2007-10-02 23:37:01 -0600 (Tue, 02 Oct 2007) $ $Revision: 25515 $
 
27
   $Date: 2008-06-12 11:44:00 +0100 (Thu, 12 Jun 2008) $ $Revision: 26630 $
28
28
   */
29
29
 
30
30
/* NOTES        -       Richard Frith-Macdonald 1997
1525
1525
 
1526
1526
  if ([coder allowsKeyedCoding])
1527
1527
    {
 
1528
      // FIXME
1528
1529
      obj = [coder decodeObject];
1529
1530
    }
1530
1531
  else
1539
1540
  return self;
1540
1541
}
1541
1542
 
 
1543
- (BOOL) writeToFile: (NSString *)path
 
1544
             options: (NSUInteger)writeOptionsMask
 
1545
               error: (NSError **)errorPtr
 
1546
{
 
1547
  return NO;
 
1548
}
 
1549
 
 
1550
- (BOOL) writeToURL: (NSURL *)url
 
1551
            options: (NSUInteger)writeOptionsMask
 
1552
              error: (NSError **)errorPtr
 
1553
{
 
1554
  return NO;
 
1555
}
1542
1556
@end
1543
1557
 
1544
1558
/**
1776
1790
  unsigned      length = [self length];
1777
1791
  void          *bytes = [self mutableBytes];
1778
1792
 
1779
 
  [aCoder encodeValueOfObjCType: @encode(unsigned int)
1780
 
                             at: &length];
1781
 
  if (length)
 
1793
  if ([aCoder allowsKeyedCoding])
1782
1794
    {
1783
 
      [aCoder encodeArrayOfObjCType: @encode(unsigned char)
1784
 
                              count: length
1785
 
                                 at: bytes];
 
1795
      [aCoder encodeBytes: bytes
 
1796
                  length: length
 
1797
                  forKey:@"NS.data"]; 
 
1798
    }
 
1799
  else
 
1800
    {  
 
1801
      [aCoder encodeValueOfObjCType: @encode(unsigned int)
 
1802
              at: &length];
 
1803
      if (length)
 
1804
        {
 
1805
          [aCoder encodeArrayOfObjCType: @encode(unsigned char)
 
1806
                  count: length
 
1807
                  at: bytes];
 
1808
        }
1786
1809
    }
1787
1810
}
1788
1811
 
1800
1823
- (id) initWithCoder: (NSCoder*)aCoder
1801
1824
{
1802
1825
  unsigned      l;
1803
 
  NSZone        *zone;
1804
 
 
 
1826
 
 
1827
  if ([aCoder allowsKeyedCoding])
 
1828
    {
 
1829
      const uint8_t *data;
 
1830
 
 
1831
      data = [aCoder decodeBytesForKey: @"NS.data"
 
1832
                       returnedLength: &l]; 
 
1833
      self = [self initWithBytes: data length: l];
 
1834
    }
 
1835
  else
 
1836
    {  
 
1837
      [aCoder decodeValueOfObjCType: @encode(unsigned int) at: &l];
 
1838
      if (l)
 
1839
        {
 
1840
          void *b;
 
1841
          NSZone        *zone;
 
1842
          
1805
1843
#if     GS_WITH_GC
1806
 
  zone = GSAtomicMallocZone();
 
1844
          zone = GSAtomicMallocZone();
1807
1845
#else
1808
 
  zone = [self zone];
 
1846
          zone = [self zone];
1809
1847
#endif
1810
 
 
1811
 
  [aCoder decodeValueOfObjCType: @encode(unsigned int) at: &l];
1812
 
  if (l)
1813
 
    {
1814
 
      void      *b = NSZoneMalloc(zone, l);
1815
 
 
1816
 
      if (b == 0)
1817
 
        {
1818
 
          NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
1819
 
          RELEASE(self);
1820
 
          return nil;
1821
 
        }
1822
 
      [aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
1823
 
      self = [self initWithBytesNoCopy: b length: l];
1824
 
    }
1825
 
  else
1826
 
    {
1827
 
      self = [self initWithBytesNoCopy: 0 length: 0];
 
1848
          
 
1849
          b = NSZoneMalloc(zone, l);
 
1850
          
 
1851
          if (b == 0)
 
1852
            {
 
1853
              NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
 
1854
              RELEASE(self);
 
1855
              return nil;
 
1856
            }
 
1857
          [aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
 
1858
          self = [self initWithBytesNoCopy: b length: l];
 
1859
        }
 
1860
      else
 
1861
        {
 
1862
          self = [self initWithBytesNoCopy: 0 length: 0];
 
1863
        }
1828
1864
    }
1829
1865
  return self;
1830
1866
}